useReducer vs useState (1) 썸네일형 리스트형 [React]리엑트 살펴보기6: useReducer 사용 방법 useReducer는 useState처럼 함수 컴포넌트에서 상태관리를 위해 사용하는 훅이다. 하지만, 다양한 숫자의 state를 관리할 때 이점이 있다. 이 Hook 함수를 사용하면 컴포넌트의 상태 업데이트 로직을 컴포넌트에서 분리시키고 별도의 파일에서 관리하기가 좋다. 1. 문법 function reducer(state: any, action: any) { switch (action.type) { case "INCREAMENT": return state + action.payload; case "DECREAMENT": return state - action.payload; default: return state; } } function App() { // const [number, setNumber] .. 이전 1 다음