TypeError:TypeError:未定义不是对象(正在评估“ props.navigationState.index”)

时间:2018-12-30 15:54:44

标签: react-native

我显示了此错误,但我不知道为什么:

  

[15:52:26] TypeError:TypeError:未定义不是对象   (评估“ props.navigationState.index”)

     

此错误位于:       在tabBarComponent中(在createBottomTabNavigator.js:72处)       在RCTView中(在View.js:45)       在视图中(在createBottomTabNavigator.js:102处)       在TabNavigationView中(在createTabNavigator.js:197处)       在NavigationView中(由Navigator创建)       在导航器中(由SceneView创建)       在SceneView中(在DrawerView.js:149处)       在RCTView中(在View.js:45)       在视图中(在ResourceSavingScene.js:20处)       在RCTView中(在View.js:45)       在视图中(在ResourceSavingScene.js:16处)       在ResourceSavingScene中(位于DrawerView.js:148)       在RCTView中(在View.js:45)       在视图中(在screens.native.js:83处)       在ScreenContainer中(在DrawerView.js:138处)       在RCTView中(在View.js:45)       在View中(在createAnimatedComponent.js:153处)       在AnimatedComponent中(在DrawerLayout.js:323处)       在RCTView中(在View.js:45)       在View中(在createAnimatedComponent.js:153处)       在AnimatedComponent中(在DrawerLayout.js:322处)       在Handler中(在DrawerLayout.js:358)       在DrawerLayout中(位于DrawerView.js:161)       在DrawerView中(由Navigator创建)       在导航器中(位于createAppContainer.js:388)       在NavigationContainer中(在routes.js:42处)       在_class中(在App.js:53)       在提供程序中(在App.js:52)       在App中(在registerRootComponent.js:17处)       在RootErrorBoundary中(在registerRootComponent.js:16处)       在ExpoRootComponent中(在renderApplication.js:34处)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:98)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:115)       在AppContainer中(位于renderApplication.js:33)

     

此错误位于:       在NavigationContainer中(在routes.js:42处)       在_class中(在App.js:53)       在提供程序中(在App.js:52)       在App中(在registerRootComponent.js:17处)       在RootErrorBoundary中(在registerRootComponent.js:16处)       在ExpoRootComponent中(在renderApplication.js:34处)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:98)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:115)       在AppContainer中(在renderApplication.js:33处)   * tabBarComponent中的src / modules / BoardScreen / index.js:21:58   -node_modules / react-native / Libraries / Renderer / oss / ReactNativeRenderer-dev.js:12020:22   在mountIndeterminateComponent中   -node_modules / react-native / Libraries / Renderer / oss / ReactNativeRenderer-dev.js:16075:21   在performUnitOfWork中   -...还有14个来自框架内部的堆栈框架

它在以下代码行中:

                            active={props.navigationState.index === 0}

我的index.js就像这样:

export default (MainScreenNavigator = createBottomTabNavigator(
    {
        Tasks: { screen: Tasks },
        Members: { screen: Members },
        Chat: { screen: Chat }
    },
    {
        tabBarPosition: "bottom",
        tabBarComponent: props => {
            return (
                <Footer>
                    <FooterTab>
                        <Button
                            vertical
                            active={props.navigationState.index === 0}
                            onPress={() => props.navigation.navigate("Tasks")}>
                            <Icon name="bookmarks" />
                            <Text>Tasks</Text>
                        </Button>
                        <Button
                            vertical
                            active={props.navigationState.index === 1}
                            onPress={() => props.navigation.navigate("Members")}>
                            <Icon name="people" />
                            <Text>Members</Text>
                        </Button>
                        <Button
                            vertical
                            active={props.navigationState.index === 2}
                            onPress={() => props.navigation.navigate("Chat")}>
                            <Icon name="git-branch" />
                            <Text>Chat</Text>
                        </Button>
                    </FooterTab>
                </Footer>
            );
        }
    }
));

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:2)

根据trim(),应为props.navigation.state.index