aotoyae

[React] input 체크박스 ERROR : You provided a `checked` prop to a form field without an `onChange` handler 본문

React

[React] input 체크박스 ERROR : You provided a `checked` prop to a form field without an `onChange` handler

aotoyae 2024. 3. 16. 16:36

 

 

💡 체크박스 에러 발견..

 

<input
  type="checkbox"
  checked={todo.isDone}
  onClick={() => toggleTodohandler(todo.id, todo.isDone)}
/>

 

체크박스에 이벤트를 onClick 으로 주었더니 에러가 떴다.

onChange 를 쓰거나 readOnly 를 붙여주라고..!

 

<input
  type="checkbox"
  checked={todo.isDone}
  onChange={() => toggleTodohandler(todo.id, todo.isDone)}
/>

 

바꿔주니 에러 없이 잘 동작한다. 🫠