title: How can I add checkbox values to setState array in reactJS
body: <p>I know this question has been asked before but I have an array I'm looping over the array getting data from that array and displaying that data in a list and in that list I have checkbox I want to get some data when the checkbox is ticked and store in a state array</p>
  <p>this is my code so far, the issue that I am having now is that the first click on the first checkbox registers as an empty array and the consecutive clicks after store the values in the array I think that us due to the fact that useState is set to empty how can I change the code so that I store the values of the checkbox in an array to be used later</p>
  <pre class="lang-js prettyprint-override"><code>
      const [checkList, setCheckList] = useState([]);
      
      const handleChange = e =&gt; {
          setCheckList([...checkList, e]);
          setChecked(prev =&gt; !prev);
          console.log(checkList);
        };
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>
      &lt;List&gt;
            {someList.map(w =&gt; (
              &lt;ListItem key={w.id}&gt;
                &lt;ListItemIcon&gt;
                  &lt;ReactSVG
                    style={{ height: '35px', width: '35px' }}
                    src={w.logo}
                  /&gt;
                &lt;/ListItemIcon&gt;
                &lt;ListItemText primary={w.name} /&gt;
                &lt;ListItemSecondaryAction&gt;
                  &lt;Checkbox
                    edge=&quot;end&quot;
                    onChange={e =&gt; handleChange(e.target.value)}
                    value={w.id}
                    // checked={checked}
                  /&gt;
                &lt;/ListItemSecondaryAction&gt;
              &lt;/ListItem&gt;
            ))}
          &lt;/List&gt;
      
  </code></pre>