title: Update initial useState of object - TypeScript , ReactJS
body: <p>Hey guys i am currently new at TypeScript and i am trying to have a state value that conatins only objects . At the moment i have an array of objects like this :</p>
  <pre><code>[{ Ananas: &quot;A&quot;, Banana: &quot;B&quot; , Citroen: &quot;C&quot;}] 
  </code></pre>
  <p>, but the ultimate goal would be to have something like this :</p>
  <pre><code>{ Ananas: &quot;A&quot;, Banana: &quot;B&quot; , Citroen: &quot;C&quot;}
  </code></pre>
  <p>I was defining my initial state like this</p>
  <pre><code>const [selectValue, setSelectValue] = useState&lt;Array&lt;string&gt;&gt;([]);
  </code></pre>
  <p>And now i try something like this , but i think is not the correct way to have initial state of objects only</p>
  <pre><code> const [selectValue, setSelectValue] = useState({});
  </code></pre>
  <p>My update function is as simple as that</p>
  <pre><code>  const handleChange = (e: any) =&gt; {
    
      setSelectValue((selectValue: any) =&gt; {
        const newSelectValue = [...selectValue];
        if (!newSelectValue[0]) newSelectValue[0] = {};
        newSelectValue[0] = { ...newSelectValue[0], [e.target.value]: e.target.name };
        return newSelectValue;
      });
    };
  </code></pre>
  <p>But as i said from above i want to update the state value to contain only objects and not an array of objects . So i wonder how can i do that.  Thanks upfront</p>