启动博览会应用程序时,我随机得到一个错误,它说:
它表示错误在这里,我不确定是什么原因引起的。 (之前不存在)
import React from "react";
import { createAppContainer, createSwitchNavigator } from "react-navigation";
import { createStackNavigator } from "react-navigation-stack";
import { createBottomTabNavigator } from "react-navigation-tabs";
import AccountScreen from "./src/screens/AccountScreen";
import CreateScreen from "./src/screens/CreateScreen";
import HomeScreen from "./src/screens/HomeScreen";
import ItemDetailScreen from "./src/screens/ItemDetailScreen";
import SigninScreen from "./src/screens/SigninScreen";
import SignupScreen from "./src/screens/SignupScreen";
import { Provider as AuthProvider } from "./src/context/AuthContext";
import { setNavigator } from "./src/navigationRef";
const switchNavigator = createSwitchNavigator({
loginFlow: createStackNavigator({
Signup: SignupScreen,
Signin: SigninScreen
}),
mainFlow: createBottomTabNavigator({
itemListFlow: createStackNavigator({
Home: HomeScreen,
ItemDetail: ItemDetailScreen
}),
Create: CreateScreen,
Account: AccountScreen
})
});
const App = createAppContainer(switchNavigator);
export default () => {
return (
<AuthProvider>
<App
ref={navigator => {
setNavigator(navigator)
}}
/>
</AuthProvider>
);
};
答案 0 :(得分:0)
应用程序呈现,然后App
组件使用其当前引用调用setNavigator
,然后由于setNavigator
函数中发生的一切而重新渲染,并永久重复直到调用堆栈达到最大深度。
如果无法查看该功能,则很难准确回答正在发生的事情。但总的来说,您完全不必使用ref。从您所见,仅<App />
就可以了,因为您已经将其初始化为switchNavigator
。