title: React useEffect cleanup with current props
body: <p>I ran into a need of cleaning a useEffect when component is unmounted but with an access to the current props. Like componentWillUnmount can do by getting this.props.whatever</p>
  
  <p>Here is a small example:
  Click "set count" button 5 times and look at your console. You'll see 0 from the console.log in component B, regardless "count" will be 5
  <a href="https://codesandbox.io/embed/vibrant-feather-v9f6o" rel="nofollow noreferrer">https://codesandbox.io/embed/vibrant-feather-v9f6o</a></p>
  
  <p>How to implement the behavior of getting current props in useEffect cleanup function (5 in my case)?</p>
  
  <p><strong>UPDATE:</strong>
  Passing count to the dependencies of useEffect won't help because:</p>
  
  <ol>
  <li>Cleanup will be invoked on every new count is passed to the props</li>
  <li>The last value will be 4 instead of the desired 5</li>
  </ol>