在 React Native 中将数据从一个场景传递到另一个场景

Pass data From one Scene to another in ReactNaive

我是 React Native 的新手,我有两个场景 OnceScene 和 TwoScene 我想从 OnceScene 导航到 TwoScene 同时我想从第一个到第二个传递一些字符串或数组所以我有写了下面的代码

 let nextRoute = {
      component: TwoScene,
      title: 'TwoScene',
      passProps: { myProp: 'bar', searchText: 'pass data', }
    };
                this.props.navigator.push(nextRoute);

你可以看到我在 passProps 中传递了字符串,但是我如何在 TwoScene 中访问该字符串它看起来很简单但是因为我是新手所以我不太清楚。

我相信 myPropsearchText 应该 在 TwoScene

中像 this.props.myPropthis.props.searchText 一样可以访问

你可以把这个写到 TwoScene:

const { params } = this.props.navigation.state;

在参数中,你得到传递数据:

params.passProps.myProp