title: react does not memorize state
body: <p>I have the following problem, i set the opacity of an element depending on the useState, but if i go another route, the opacity sets back to 0</p>
  <pre><code>const [phoneVisible, setPhoneVisible] = useState(false);
  
  useLayoutEffect(() =&gt; {
    if (toggleEvent !== &quot;undefined&quot;) {
      setTimeout(() =&gt; {
        animatePhone(phoneRef, toggleEvent);
        setPhoneVisible(toggleEvent);
      }, 100);
    }
  }, [phoneRef, toggleEvent]);
  
  return (
  &lt;&gt;
        &lt;div
          ref={phoneRef}
          style={{ opacity: phoneVisible ? 1 : 0 }}
          className=&quot;relative w-screen h-screen&quot;
        &gt;
        ...
        &lt;/div&gt;
  
  &lt;/&gt;
  );
  </code></pre>
  <p>Im out of ideas, thanks for your help</p>