React native 笔记:自定义子组件接受带参函数 子组件传递参数给父组件 函数

本文介绍如何在React中实现子组件通过带参函数向父组件传递参数的方法。具体展示了父组件定义带参函数并将其作为属性传递给子组件,子组件通过props调用这些函数并附带参数,实现数据的逆向流动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在子组件接受带参函数,传递参数给父组件函数

父组件:

<IDTypeDialogView hide={()=>{ this.hideCoverLayer()}}
                  type={(type)=>{this.setStateCredentials_type(type)}}/>

父组件函数:

setStateCredentials_type(type) { //带参
    this.setState({credentials_type: type});
}
hideCoverLayer() {//无参
    this.coverLayer.hide();
}

 

自定义子组件 :props.方法名.bind(null,'参数')

const IDTypeDialogView = props => (
    <View style={{height: 138, width: DEVICE_WIDTH, backgroundColor: 'white'}}>
        <View style={{
            flex: 1,
            flexDirection: 'row',
            height: 45,
            paddingLeft: 15,
            paddingRight: 15,
            alignItems: 'center',
            justifyContent: 'space-between',
        }}>
            <Text onPress={props.hide}>Cancel</Text>
            <Text style={{color: '#3d61ff'}} onPress={props.hide}>Ok</Text>
        </View>
        <View>
            <Text style={{height: 45, alignSelf: 'center'}} onPress={props.type.bind(null,'Passport')}>Passport</Text>
            <Text style={{height: 45, alignSelf: 'center'}} onPress={props.type.bind(null,'ID Card')}>ID Card</Text>
        </View>
    </View>
);

export default IDTypeDialogView;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值