title: how to update a state object in react?
body: <p>I define the state</p>
  <pre><code>const [newOption, setNewOption] = useState({ name: &quot;&quot;, age: 30 });
  </code></pre>
  <p>then I want to update it.</p>
  <pre><code>&lt;input
      type=&quot;text&quot;
      value={newOption.name}
      onChange={(e) =&gt; setNewOption((prevState) =&gt; ({...prevState, name: e.target.value}))}
  /&gt;
  </code></pre>
  <p>but I get TypeError: Cannot read property 'value' of null when I start typing</p>
  <p>I need to pass the event but how?</p>