Inflearn Community Q&A
handleSubmit을 useCallback으로
Resolved
Written on
·
460
0
handleSubmit를 useCallback으로 감싸서 만들어봤는데
const handleSubmit = useCallback(
(e) => {
e.preventDefault();
let newTodoData = todoData.map((data) => {
if (data.id === id) {
data.title = editedTitle;
}
return data;
});
console.log(newTodoData);
setTodoData(newTodoData);
setIsEditing(false);
},
[todoData, setTodoData, id, editedTitle]
);의존성배열에 setTodoData 를 넣지않으면 아래오류가 나면서 handleSubmit 함수가 실행되지 않더라구요
React Hook useCallback has a missing dependency: 'setTodoData'. Either include it or remove the dependency array. If 'setTodoData' changes too often, find the parent component that defines it and wrap that definition in
useCallback제 지식으론 의존성배열에 todoData만 넣으면 될줄 알았는데 왜 setTodoData 까지 같이 넣어야하는지 궁금합니다!
reactreduxtddtypescriptnext.js
Quiz
When creating a project with Create React App, what is the main tool that helps with development convenience by compressing and transforming code?
Webpack and React Router
Babel and Redux
Webpack and Babel
HTML5 History API and DOM
Answer 1
0
John Ahn
Instructor
안녕하세요 ~ 안 넣어주셔도 됩니다 ~
린트에서 전달해 준 경고는 다 정확한 부분은 아닙니다 ~
감사합니다!
https://github.com/reactjs/reactjs.org/blob/main/content/docs/hooks-reference.md#usestate-usestate





