react-native navigation页面回调函数callback

本文介绍在React Native中如何通过navigation进行页面间的数据回调,实现前一个页面获取到跳转后页面处理结果的方法。

react-native 在使用navigation进行页面跳转时,有时前一个页面需要知道跳转后的页面的处理结果,这时我们可以用回调函数的方式进行回调数据结果

 

ScreenA
this.props.navigation.navigate('screenB', {
    callBack: (result) => this.setState({res:result});
});


ScreenB
if(this.props.navigation.state.params.callBack) {
    this.props.navigation.params.callBack('abc');
}




 

D:\AwesomeProject>npm ls react [email protected] D:\AwesomeProject +-- @ant-design/icons-react-native@2.3.2 | `-- react@17.0.2 deduped +-- @ant-design/react-native@5.4.2 | +-- @floating-ui/react-native@0.10.7 | | `-- react@17.0.2 deduped | +-- rc-field-[email protected] | | `-- react@17.0.2 deduped | +-- rc-[email protected] | | `-- react@17.0.2 deduped | +-- react-native-[email protected] | | `-- react@17.0.2 deduped | +-- react-native-modal-[email protected] | | `-- react@17.0.2 deduped | `-- react@17.0.2 deduped +-- @react-native-community/[email protected] | `-- react@17.0.2 deduped +-- @react-native-community/masked-[email protected] | `-- react@17.0.2 deduped +-- @react-native-community/segmented-[email protected] | `-- react@17.0.2 deduped +-- @react-native-community/[email protected] | `-- react@17.0.2 deduped +-- @react-native-community/[email protected] | `-- react@17.0.2 deduped +-- @react-native-picker/[email protected] | `-- react@17.0.2 deduped +-- @react-navigation/native-[email protected] | +-- @react-navigation/[email protected] | | `-- react@17.0.2 deduped | `-- react@17.0.2 deduped +-- @react-navigation/native@6.1.18 | +-- @react-navigation/[email protected] | | +-- react@17.0.2 deduped | | `-- use-latest-callback@0.2.4 | | `-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings | `-- react@17.0.2 deduped +-- @rneui/[email protected]-rc.8 | `-- react-native-[email protected] | `-- react@17.0.2 deduped +-- react-native-[email protected] | `-- react-native-[email protected] | `-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings +-- react-native-exception-[email protected] | `-- react@17.0.2 deduped +-- react-native-image-[email protected] | `-- react@17.0.2 deduped +-- react-native-image-zoom-[email protected] | +-- react-native-image-pan-[email protected] | | `-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings | `-- react@17.0.2 deduped +-- react-native-linear-[email protected] | `-- react@17.0.2 deduped +-- react-native-[email protected] | `-- react@17.0.2 deduped +-- react-native-[email protected] invalid: ">=3.10.1" from node_modules/@ant-design/react-native | `-- react@17.0.2 deduped +-- react-native-safe-area-[email protected] | `-- react@17.0.2 deduped +-- react-native-[email protected] | +-- react-[email protected] | | `-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings | `-- react@17.0.2 deduped +-- react-native-svg-[email protected] | `-- react@17.0.2 deduped +-- react-native-[email protected] | `-- react@17.0.2 deduped +-- react-native@0.68.0 | +-- react-shallow-[email protected] | | `-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings | +-- react@17.0.2 deduped | `-- use-[email protected] | +-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings | `-- use-sync-external-[email protected] | `-- react@17.0.2 deduped invalid: "^16.0.0" from node_modules/react-native-elements/node_modules/react-native-ratings +-- react-[email protected] | `-- react@17.0.2 deduped +-- react-test-[email protected] | `-- react@17.0.2 deduped `-- react@17.0.2 npm error code ELSPROBLEMS npm error invalid: react@17.0.2 D:\AwesomeProject\node_modules\react npm error A complete log of this run can be found in: C:\Users\临时\AppData\Local\npm-cache\_logs\2025-08-01T01_11_42_653Z-debug-0.log
最新发布
08-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值