将父数据传递到子屏幕(抽屉导航)

时间:2020-09-09 03:07:35

标签: react-native react-navigation react-props

我正在尝试将状态数据从App.js传递到我的抽屉屏幕,该屏幕位于另一个文件中,但道具无法检索该数据。

App.js

render() {
  return (
    <GalioProvider theme={argonTheme}>
      <Block flex>
      <Screens user={this.state.user} />
      </Block>
    </GalioProvider>
  );
}

Screen.js

const AppStack = createDrawerNavigator(
  {
    Home: {
      screen: HomeStack,
      navigationOptions: (navOpt) => ({
        drawerLabel: ({ focused }) => (
          <DrawerItem focused={focused} title="Home" />
        ),
      }),
    },
  },
  {
    contentComponent: (props) => {
      console.log(props.user);
      return (
        <View
          style={{ flex: 1, alignItems: "center", justifyContent: "center" }}
        ></View>
      );
    },
  }
);

const AppContainer = createAppContainer(AppStack);
export default AppContainer;

console.log(props.user)行返回undefined

0 个答案:

没有答案