title: setState action wit setTimeout brings back removed elements
body: <p>I'm trying to make toast notifications in my project by myself and I'm almost there but I have a little problem now. I set up my notifications and made it disappear on click. But then I added setTimeout to remove toast from my state after 5 seconds and it doesn't work as I expected. When there is one notification it works as it should, but when there is more that one notifications it removes all the toasts, and then brings back all except the last one. I think there is a problem with my setState action in removeToast function.</p>
  <p>Deleting one by one works properly.</p>
  <p>Code:</p>
  <pre><code>const useToastsContainer = createContainer(() =&gt; {
      const [toasts, setToasts] = useState&lt;ToastItem[]&gt;([]);
  
      useEffect(() =&gt; {
          console.log(toasts);
      }, [toasts]);
  
      const removeToast = (id: string) =&gt; {
          setToasts(toasts.filter((item) =&gt; item.id !== id));
      };
  
      const createToast = (type: ToastType, content: string) =&gt; {
          const id = v4();
          const toast = {
              id,
              type,
              content,
          };
          setToasts([...toasts, toast]);
          setTimeout(() =&gt; {
              removeToast(id);
          }, 5000);
      };
  
      return {
          toasts,
          removeToast,
          createToast,
      };
  });
  </code></pre>
  <p><a href="https://codesandbox.io/s/inspiring-bose-0u1rb?fontsize=14&amp;hidenavigation=1&amp;theme=dark" rel="nofollow noreferrer"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="Edit inspiring-bose-0u1rb" /></a></p>