title: How to push an object inside nested array using React and TypeScript?
body: <p>What's the proper way, using TypeScript and React, to create a function that pushes a new object inside the array <code>items</code> ?</p>
  <pre><code>const [state, setState] = useState([
    {
      firstname: &quot;William&quot;,
      items: [
        { name: &quot;sword&quot;, damage: 100 },
        { name: &quot;shield&quot;, damage: 50 },
      ],
    },
    {
      firstname: &quot;Allison&quot;,
      items: [
        { name: &quot;bow&quot;, damage: 70 },
        { name: &quot;axe&quot;, damage: 120 },
      ],
    },
  ]);
  
  const addNewItem = (newItem: object, CharacterIndex: number) =&gt; {
  
    // Push new item inside character's items.
    setState(newState)
  };
  
  return (
    &lt;button onClick={() =&gt; addNewItem({ name: &quot;dagger&quot;, damage: 50 }, 2)}&gt;
      Add Item
    &lt;/button&gt;
  );
  </code></pre>
  <p>I have already done once using JavaScript, but with Typescript I often get some errors.</p>