0

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>
      ))
    };

screenshot

Thanks y'all for your help !!!

F4L4X
  • 17
  • 5

1 Answers1

0

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?

Sujit Libi
  • 386
  • 1
  • 4
  • 16