The child component accepts a function with parameters, and passes the parameters to the parent component function
Parent component:
<IDTypeDialogView hide={()=>{ this.hideCoverLayer()}} type={(type)=>{this.setStateCredentials_type(type)}}/>
Parent component function:
setStateCredentials_type(type) { //带参 this.setState({credentials_type: type}); }
hideCoverLayer() {//无参 this.coverLayer.hide(); }
Custom sub-component: props. Method name. Bind (null,'parameter')
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;