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;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章