Handle
-
React State HandlingComputer Science/React 2022. 9. 4. 19:56
state를 다루는 것이 비슷하다면 여러개 선언하는 것이 아닌 다음과 같이 한개의 state에 선언해준다. const [state, setState] = useState({ author: "", content: "", emotion: 1, }); handle 함수를 두고 target의 이름을 가져와서 해당 target만 변경하도록 진행한다. const handleChangeState = (e) => { setState({ ...state, [e.target.name]: e.target.value, }); }; 1 2 3 4 5