在 React Native 中跨组件传递参数
Passing params across components in ReactNative
在我的 ReactNative 应用程序中,我试图在导航堆栈中使用 "route" 跨组件传递一些数据。我发送如下代码:
navigation.navigate('OtpScreen', { otpKey: '1234' });
我在 OtpScreen 中捕获如下:
const OTPScreen = ({ navigation, route }) => {
const { otpKey }= route.params;
}
显示此屏幕时抛出未定义 'params'。
我已经浏览了 Snack
中可用的示例代码
我的代码可能有什么问题?
在你的渲染下面输入这个
const param = route.params.otpKey;
希望对您有所帮助!
我注意到在最新版本的 ReactNative 中,我必须使用下面的代码行来从导航中获取参数。
const otpKey = navigation.getParam('otpKey', '');
我想,我们不能再使用"parmas"了。
在我的 ReactNative 应用程序中,我试图在导航堆栈中使用 "route" 跨组件传递一些数据。我发送如下代码:
navigation.navigate('OtpScreen', { otpKey: '1234' });
我在 OtpScreen 中捕获如下:
const OTPScreen = ({ navigation, route }) => {
const { otpKey }= route.params;
}
显示此屏幕时抛出未定义 'params'。 我已经浏览了 Snack
中可用的示例代码我的代码可能有什么问题?
在你的渲染下面输入这个
const param = route.params.otpKey;
希望对您有所帮助!
我注意到在最新版本的 ReactNative 中,我必须使用下面的代码行来从导航中获取参数。
const otpKey = navigation.getParam('otpKey', '');
我想,我们不能再使用"parmas"了。