title: Use react navigation.navigate inside a normal function - (no hooks allowed i.e. useNavigation)?
body: <p>I'm trying to put a function that navigates to a screen in an other module and export it, but <code>navigation</code> does not work. I tried with <code>UseNavigation()</code> but I get an error, namely: <code>Unhandled promise rejection: Invariant Violation: Hooks can only be called inside the body of a function component.</code></p>
  
  <p>Is there a way to use navigation in a normal function, or anything else.</p>
  
  <pre class="lang-js prettyprint-override"><code>import React, { useState, useEffect, useCallback } from "react";
  import { AsyncStorage, Alert } from "react-native";
  import { useNavigation } from "react-navigation-hooks";
  
  export const startMixGame = async (categoryIsChosen, withTimer) =&gt; {
    const navigation = useNavigation();
  
    if (categoryIsChosen) {
      if (withTimer) {
        await AsyncStorage.setItem("useTimer", "true");
        navigation.navigate({
          routeName: "MixedQuestions",
          params: {
            categoryId: "1"
          }
        });
      } else if (!withTimer) {
        // console.log("withTimer", withTimer);
  
        await AsyncStorage.setItem("useTimer", "false");
        navigation.navigate({
          routeName: "NoTimerMixedQuestions",
          params: {
            categoryId: "1"
          }
        });
      }
    }
  
  };
  
  </code></pre>
  
  <p>Thanks</p>