title: useState and splice react
body: <p>I have a big problem with useState in react..<br>
  I just want to remove an object from an array using slice and setState this array using hooks.<br>
  But it's not working I don't know why ..  </p>
  
  <p>Look:</p>
  
  <pre><code>  const [ img, setImg ] = useState(allImages);
  
    const removeImageAtIndex = (index) =&gt; {
      img.splice(index, 1); // when i console.log i can see that the object has been removed
      setImg(img);         // nothing changes
      /* FOR TEST
      setImg([]); // if I remove all img, it's working 
      */
      /* I already tried this:
      let temp = img;
      img.splice(index, 1);
      setImg(temp);
      */
    /* SOLUTION
      setImg([...img]);
    */
    };
  
    return (
      &lt;div&gt;
        { variants.map((variant, index) =&gt; {
          return &lt;img key={index } onClick={ () =&gt; removeImageAtIndex(index)} src={img.src} /&gt;
        })}
      &lt;/div&gt;
  </code></pre>
  
  <p>Thanks !</p>