简体   繁体   English

如何在 react-native 中的两个功能组件之间传递数据?

[英]How to pass data between two functional components in react-native?

I am trying to pass data between two functional components but getting undefined value.我试图在两个功能组件之间传递数据但得到undefined值。

File1.js //functional Component 1 File1.js //功能组件1

const file1 = ({navigation}) => {
      navigation.navigate('file2',{data:"Hello"});
};

File2.js //functional Component 2 File2.js //功能组件2

const file2 = ({navigation}) => {
  console.log(navigation.getParam("data");
};

My Solution我的解决方案

File1.js //functional Component 1 File1.js //功能组件1

const file1 = ({navigation}) => {
      navigation.navigate('file2',{item :"Hello"});
};

File2.js //functional Component 2 File2.js //功能组件2

const file2 = (props) => {
  console.log(props.data.item);
};

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM