Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 439 Bytes

react-checkbox-onchange.md

File metadata and controls

22 lines (17 loc) · 439 Bytes

How to handle checkbox change in React

In order to react on a checkbox value change, you should:

  1. Define a function to handle updates:
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
  const { checked } = e.target;
};
  1. Use this function in the onChange attribute:
<input
  type="checkbox"
  id="remote_work_allowed"
  name="remote_work_allowed"
  onChange={(e) => handleChange(e)}
/>