Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array 객체
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
Archives
- Today
- In Total
A Joyful AI Research Journey🌳😊
Differences between Spring/JSP and React/TypeScript for CRUD Operations 본문
💻Bootcamp Self-Study Revision✨/JavaScript, jQuery, Ajax
Differences between Spring/JSP and React/TypeScript for CRUD Operations
yjyuwisely 2023. 7. 31. 14:57
Differences between Spring/JSP and React/TypeScript for CRUD Operations:
Easiest Way to Make CRUD Function Using React:Building CRUD functionality in React involves setting up components that handle the different parts of the CRUD functionality: Create, Read, Update, and Delete.Here's a general step-by-step guide:
|
import React, { useEffect, useState } from 'react';
const List = () => {
const [data, setData] = useState([]);
useEffect(() => {
fetch('/api/data')
.then(response => response.json())
.then(data => setData(data));
}, []);
return (
<div>
{data.map(item => (
<div key={item.id}>
{/* Display your data here */}
</div>
))}
</div>
);
};
export default List;
3. Create a Form Component: This component will handle both creation of new items and updating existing ones. It should have form controls for all the fields of your data, and it should use controlled components to handle form state. 4. Handle Create and Update: You'll need to have functions to handle the form submissions. They should prevent the default form submission, take the data from the state, and then use fetch to send the data to the server. Depending on whether you're creating a new item or updating an existing one, you'll send a POST or PUT request. 5. Handle Delete: This could be a button next to each item in your list. When clicked, it should use fetch to send a DELETE request to the server with the id of the item to delete. 6. State and Props: Use the state in your components to hold and manage data, and pass down functions as props to handle the Create, Update, and Delete operations. Remember to use TypeScript to type your props, state, and events. This will provide you with autocompletion and help catch errors before they happen. React with TypeScript can be challenging at first but it is worth it in the long term for maintainability and reliability of the code. Also note that in real-world scenarios, you might want to consider using a state management library (like Redux or MobX) for better state management and a library like react-query or SWR for data fetching, but these aren't strictly necessary for smaller applications. |
728x90
반응형
'💻Bootcamp Self-Study Revision✨ > JavaScript, jQuery, Ajax' 카테고리의 다른 글
JavaScript: reduce() (0) | 2023.07.31 |
---|---|
The pros and cons of using Axios and Fetch API (0) | 2023.07.31 |
JavaScript: Greatest Common Divisor (최대 공약수), Least Common Multiple (최소 공배수) (0) | 2023.06.29 |
JavaScript: padStart, padEnd, map() (0) | 2023.06.28 |
Comments