简体   繁体   English

'TypeError:无法读取 react-native 中未定义'的属性'getStateForAction'

[英]'TypeError: Cannot read property 'getStateForAction' of undefined ' in react-native

In my react-native project,在我的 react-native 项目中,

i installed follwing我安装了以下

npm install @react-navigation/native @react-navigation/stack

after edit my 'app.js' file like below,在编辑我的“app.js”文件后,如下所示,

 import {createAppContainer, createSwitchNavigator} from 'react-navigation' import {createStackNavigator} from 'react-navigation-stack' import HomeScreen from './screens/HomeScreen' import LoadingScreen from './screens/LoadingScreen' import LoginScreen from './screens/LoginScreen' import RegisterScreen from './screens/RegisterScreen' const AppStack=createStackNavigator({ Home:HomeScreen }); const AuthStack=createStackNavigator({ Login:LoginScreen }); export default createAppContainer(( { Loading:LoadingScreen, App:AppStack, Auth:AuthStack }, { initialRouteName:"Loading" } ));

HomeScreen, LoadingScreen, LoginScreen, RegisterScreen are I created classes extend by 'React.Component' HomeScreen、LoadingScreen、LoginScreen、RegisterScreen 是我创建的由“React.Component”扩展的类

when i run the project, it gives follwing run time error.当我运行该项目时,它会给出以下运行时错误。

TypeError: Cannot read property 'getStateForAction' of undefined

在此处输入图像描述

How I solve this run time error?我如何解决这个运行时错误?

You are trying to use the stacks directly inside the container,You can use a single stack or use the switch navigator that you have imported like below您正在尝试直接在容器内使用堆栈,您可以使用单个堆栈或使用您已导入的开关导航器,如下所示

const switchNav=createSwitchNavigator(
  {
    AuthLoading: AuthLoadingScreen,
    App: AppStack,
    Auth: AuthStack,
  },
  {
    initialRouteName: 'AuthLoading',
  }
);

export default createAppContainer(switchNav);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "React-Native AsyncStorage:TypeError:无法读取未定义的属性“setItem”" - React-Native AsyncStorage: TypeError: Cannot read property 'setItem' of undefined react-native - 类型错误:无法读取未定义的属性“修剪” - react-native - TypeError: Cannot read property 'trim' of undefined react-native redux登录表单抛出'TypeError:无法读取未定义的属性'displayName''' - react-native redux Login Form throws an 'TypeError: Cannot read property 'displayName' of undefined'' React-Native Navigator:无法读取未定义的属性“ push” - React-Native Navigator: Cannot read property 'push' of undefined 无法在react-native上下文api中读取未定义的属性“状态”? - Cannot read property 'state' of undefined in react-native context api? 如何解决无法读取react-native上未定义的属性“ push”? - how to solve Cannot read property 'push' of undefined on react-native? React-native:无法读取未定义的属性“ navigate” - React-native:cannot read property 'navigate' of undefined 类型错误:无法读取 React Native 中未定义的属性“set” - TypeError: Cannot read property 'set' of undefined in React native React Native [TypeError:无法读取未定义的属性'startsWith']? - React Native [TypeError: Cannot read property 'startsWith' of undefined]? React Native TypeError:无法读取未定义的属性'projectName' - React Native TypeError: Cannot read property 'projectName' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM