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

How to pass data From one Scene to another in ReactNaive

我的问题我有两个场景 OnceSceneTwoScene 我想从 OnceScene 导航到 TwoScene 同时我想传递一些数组第一次和第二次所以我写了下面的代码

 this.props.navigator.push({
     id: "productdetails",

passProps: {arr: arr[rowID]}

   });

你可以看到我正在传递 passProps 中的数组,但是我如何在 TwoScene 中访问该数组它看起来很简单但是因为我是新手所以我不太了解。

你试过使用react-native router吗?

https://github.com/aksonov/react-native-router-flux

另外,在回答您的问题时,您似乎正在通过 props 传递数据。因此,在下一个屏幕上,您可以访问这些道具,例如:this.props.foo(当然,您需要以某种方式在第二个屏幕上声明它才能访问它。)

我找到了我遗漏的东西,忘了申报

  return (<ProductDetails title="ProductDetails"

导航器={导航器}

{...route.passProps} route={route}

/>)

在我的 return 组件上。这就是我获得 undefined 价值的原因。