title: How to declare useState() initial value as null and then give it an object value later?
body: <p><a href="https://i.stack.imgur.com/TjAbz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TjAbz.png" alt="enter image description here" /></a></p>
  <p>As can be seen in the image, I want to declare a react state hook to the alert of my webpage. At first, I want that there is no alert shown. And whenever user is clicking some button, I want to show a success alert with a message (error alert if something goes wrong). I will call showAlert function to do this with message and type as function parameter. That's why there can be more than one type of alert. So, I created this alert object and attached hook with initial value &quot;NULL&quot;. But the editor gives me this error.</p>
  <pre><code>Argument of type '{ msg: any; type: any; }' is not assignable to parameter of type 'SetStateAction&lt;null&gt;'. Object literal may only specify known properties, and 'msg' does not exist in type '(prevState: null) =&gt; null'.ts(2345)
  </code></pre>
  <p>So, can someone tell me how I can tell useState the object parameters that I will allot it in future. Or should I try to hide the website alert in some other way? Here is the code..</p>
  <pre><code>const [alert, setAlert] = useState(null);
  
  const showAlert = (message, type) =&gt; {
      setAlert({
          msg: message,
          type: type,
      });
  
      setTimeout(() =&gt; {
          setAlert(null);
      }, 2000);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Dftl3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dftl3.png" alt="enter image description here" /></a></p>
  <p>This solution is not working for me.</p>