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

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

父组件:

<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;

猜你喜欢

转载自blog.csdn.net/qq_36355271/article/details/104774356
今日推荐