title: how to change value of object in array using setState with React
body: <p>hello everyone good evening,</p>
  <p>I have array of object set in state and i would like to change some object in the array.</p>
  <p>so here is my array us you can see:</p>
  <pre><code>    const [CategoriesArr, setCategoriesArr] = useState([
      {
          image: anime,
          nameByCategories: &quot;Aninate&quot;,
          allCard: [
              silverCard, blackCard
          ],
      },
      {
          image: vacation,
          nameByCategories: &quot;Vacation&quot;,
          allCard: [
              blackCard, silverCard
          ],
      },])
  </code></pre>
  <p>i tried to change the <code>allCard</code> to: <code>allCard:blackCard, blackCard</code></p>
  <p>with this way:</p>
  <pre><code>setCategoriesArr([
  {
      ...CategoriesArr[0],
      allCard: [
          silverCard, silverCard
      ]
  }])
  </code></pre>
  <p>the problem is after the setState i get new array with changes that i want and also the last array so it means like this</p>
  <pre><code>  {
          image: anime,
          nameByCategories: &quot;Aninate&quot;,
          allCard: [
              blackCard, blackCard
          ],
      },
      {
          image: vacation,
          nameByCategories: &quot;Aninate&quot;,
          allCard: [
              silverCard, blackCard
          ],
      },
    {
          image: anime,
          nameByCategories: &quot;vacations&quot;,
          allCard: [
              blackCard, silverCard
          ],
      },
  </code></pre>
  <p>i would like to understand i can i get new array exact like that:</p>
  <pre><code>    const [CategoriesArr, setCategoriesArr] = useState([
  {
      image: anime,
      nameByCategories: &quot;Aninate&quot;,
      allCard: [
          silverCard, blackCard
      ],
  },
  {
      image: vacation,
      nameByCategories: &quot;Vacation&quot;,
      allCard: [
          blackCard, blackCard
      ],
  },])
  </code></pre>
  <p>pleas.</p>
  <p>i hope you guys going to help me :)</p>