title: React get state from Redux store within useEffect
body: <p><strong>What is the correct way to get state from the Redux store within the <code>useEffect</code> hook?</strong></p>
  
  <pre><code>    useEffect(() =&gt; { 
          const user = useSelector(state =&gt; state.user);
      });
  </code></pre>
  
  <p>I am attempting to get the current state within <code>useEffect</code> but I cannot use the <code>useSelector</code> call because this results in an error stating:</p>
  
  <p><code>Invariant Violation: Hooks can only be called inside the body of a function component.</code></p>
  
  <p>I think I understand why as it breaks one of the primary rules of hooks.</p>
  
  <p>From reviewing <a href="https://codesandbox.io/s/9on71rvnyo" rel="noreferrer">the example</a> on the Redux docs they seem to use a <code>selectors.js</code> file to gather the current state but this reference the <code>mapStateToProps</code> which I understood was no longer necessary.</p>
  
  <p>Do I need to create some kind of "getter" function which should be called within the <code>useEffect</code> hook?</p>