๐ฅ useReducer์ ์ฒซ ๋ฒ์งธ ์ธ์๋ก ๋ฐ๋ reducer ํจ์๊ฐ useReducer ์ดํ์ ์ ์ธ๋๋ฉด ์ค๋ฅ๋ฐ์
const [count, countDispatch] = useReducer(countReducer, 0);
const countReducer = (prevState, action) => {
switch (action.type) {
case "DOWN": {
return prevState - 1;
}
case "RESET": {
return 0;
}
case "UP": {
return prevState + 1;
}
default:
return prevState;
}
};
๐ฉ
const countReducer = (prevState, action) => {
switch (action.type) {
case "DOWN": {
return prevState - 1;
}
case "RESET": {
return 0;
}
case "UP": {
return prevState + 1;
}
default:
return prevState;
}
};
const [count, countDispatch] = useReducer(countReducer, 0);
์์๋ฅผ ๋ฐ๊ฟ์ฃผ์๋๋ ํด๊ฒฐ๋์๋ค!