I am developing a reactJS app. I am returning checkboxes and I want to check weather the checkbox I am returning has been already checked. When a checkbox is checked the value of that checkbox is added to a list which is stored on a db. When I display a checkbox I am trying to check if that value is already in the checked list. However, it doesn't work, nothing is checked. Is the If statement correct?
const showSoftwares = () => {
return contractor.softwares.map((item, index) => (
<li key={index}>
<input type="checkbox" {...contractor.done.includes(item) ? checked: true} onChange={handleToggle(item)}></input>
<label>{item}</label>
</li>
))
};
Thanks y'all for your help !!!
You could do like this:
<input type="checkbox" defaultChecked={contractor.done.includes(item)} onChange={handleToggle(item)} />
You can get more on following link: How to set default Checked in checkbox ReactJS?