【发布时间】:2020-02-29 08:35:59
【问题描述】:
我正在尝试将导航到屏幕的功能放在另一个模块中并将其导出,但navigation 不起作用。我尝试使用UseNavigation(),但出现错误,即:Unhandled promise rejection: Invariant Violation: Hooks can only be called inside the body of a function component.
有没有办法在正常功能中使用导航,或其他任何东西。
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) => {
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"
}
});
}
}
};
谢谢
【问题讨论】:
标签: reactjs react-native react-navigation react-native-navigation