El componente secundario acepta una función con parámetros y pasa los parámetros a la función del componente principal.
Componente padre:
<IDTypeDialogView hide = {() => {this.hideCoverLayer ()}} type = {(type) => {this.setStateCredentials_type (type)}} />
Función del componente principal:
setStateCredentials_type (tipo) {// 带 参 this.setState ({credentials_type: type}); }
hideCoverLayer () {// 无 参 this.coverLayer.hide (); }
Subcomponente personalizado: props. Nombre del método. Bind (nulo, 'parámetro')
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}> Cancelar </Text> <Text style = { {color: '# 3d61ff '}} onPress = {props.hide}> Ok </Text> </View> <View> <Estilo de texto = { {height: 45, alignSelf: 'center'}} onPress = {props.type.bind (null, 'Passport')}> Pasaporte </Text> <Text style = { {height: 45, alignSelf: 'center'} } onPress = {props.type.bind (null, 'Tarjeta de identificación')}> Tarjeta de identificación </Text> </View> </View> ); exportar IDTypeDialogView predeterminado;