You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native子组件如何同时获取父组件Props与Navigation?

问题原因与解决方法

你的错误在于误解了React函数组件的参数结构——React函数组件仅接收一个props对象作为参数,不存在第二个独立参数用于获取navigation。

你在Stack.Screen中已经通过{...props}将React Navigation的导航相关props(包括navigation)传递给了SignIn组件,所以navigation已经包含在子组件的第一个props参数里了。

正确写法

写法一:从props对象中解构

const SignIn = (props) => {
  const { DIC, navigation } = props;
  // 在这里使用DIC和navigation
};

写法二:直接在参数中解构

const SignIn = ({ DIC, navigation }) => {
  // 在这里使用DIC和navigation
};

你之前尝试的const SignIn = (props, {navigation}) => {...}写法中,第二个参数实际指向的是组件的context,但此处没有对应的context提供navigation,所以才会拿到空对象。

内容的提问来源于stack exchange,提问作者Carlos del Río Francés

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 22:40:16