Alewa's avatar
Level 2

How to update my checkbox

I am having problem updating my checkbox names status which is a boolen, either 1 or 0, i can't get it actual check, if the status is 1, the checkbox should display checked and if status is 0, it should be unchecked, but when i check my status checkbox, i can't uncheck it when i want to update it.

This is my EditProductCategory.jsx file

Any help?

0 likes
1 reply
Randy_Johnson's avatar
function handleChange(e) {
    const key = e.target.id;
    const value = e.target.value
    setValues(values => ({
        ...values,
        [key]: value,
    }))
  }
<input id="first_name" 
type="checkbox" value={values.first_name} onChange={handleChange} />

Something like this

Please or to participate in this conversation.