title: useState updates state value but is passing the old value as an argument to a function
body: <p>Using the useState hook I update the state of the component (which I use to toggle an animation with react-spring) and I want to send the state's value to the redux store so I can use it on another component. </p>
  
  <p>The problem is that while the useState hook works as expected, its value that gets passed as an argument to the action that gets dispatch is the opposite of the state.</p>
  
  <p>Since the other component that gets the value from store still works fine (but always toggled on the opposite way) I assume it's not an action/reducer problem.</p>
  
  <p>useState is initialised with false.
  on click updates the useState value.
  useState value is updated correctly.
  value then passed as an argument to a redux action which gets false instead of true.</p>
  
  <pre><code>
  export const UnconnectedMenuToggle: React.FC&lt;INT.IToggleMenuProps&gt; = ({
    getToggleMenuRequest }): JSX.Element =&gt; {
  
    const [isMenuOpen, setMenuOpen] = useState&lt;boolean&gt;(false);
  
    const btnAnimation = useSpring&lt;INT.IAnimateToggle&gt;({
      transform: isMenuOpen
        ? `translate3d(300px,0,0)`
        : `translate3d(0px,0,0)`
    });
  
    const imgAnimation = useSpring&lt;INT.IAnimateToggle&gt;({
      transform: isMenuOpen
        ? `rotate(0deg)`
        : `rotate(540deg)`
    });
  
    const makeBoolGlobal = (): void =&gt; {
      setMenuOpen(isMenuOpen =&gt; !isMenuOpen)
      getToggleMenuRequest(isMenuOpen)
    }
  
    return (
      &lt;a.button
        data-test="button-toggle"
        className="menu-button"
        onClick={makeBoolGlobal}
        style={btnAnimation}
        type="button"
      &gt;
        &lt;a.img src={chevron}
          data-test="img-toggle"
          alt="Open Menu"
          style={imgAnimation}
        /&gt;
      &lt;/a.button&gt;
    )
  }
  
  
  </code></pre>
  
  <p>No error messages</p>