title: Conditional execution of 'getInitialProps' in Next.js
body: <p>I have global state management using <code>useContext</code> and <code>useReducer</code> I want to check whether the user is authenticated or not. to do so, what occurred to me, was to check inside <code>getInitialProps</code> in this way:</p>
  
  <pre><code>DashboardPage.getInitialProps = async () =&gt; {
    const [globalState, dispatch] = useContext(STORE.storeContext);
    let auth = globalState.isAuthed
    if (!auth) {
      auth = axiox.get('/authenticateThisUser');
    } 
    return {
      auth,
    }
  }
  </code></pre>
  
  <p>However, when I execute this snippet, it throws <em><code>Error: Invalid hook call. Hooks can only be called inside of the body of a function component</code></em>. how can I use <code>useContext</code> inside <code>getInitialProps</code>?</p>
  
  <p>What I'm looking for is a way to prevent components from sending redundant auth requests to
   the server.</p>
  
  <p>It would be great if there were some methods to conditionally execute <code>getInitialProps</code>
  like this: </p>
  
  <pre><code>if(globalState.isAuthed){
      //dont execute getInitialProps of this component
  }else {
      //execute getInitialProps of this component
  }
  </code></pre>