react-native-check-box
react-native-check-box copied to clipboard
makes posible to check/uncheck from parent component
I added in the component will receive props the functionality to check or uncheck the checkbox if the isChecked prop changed, this is useful when you need to toggle the checkbox. Example:
Gender: Male[ ] Female[ X ] => click male checkbox Male[ X ] Female[ ]
In this example you only will be able to have one of the checkboxes checked
class Gender extends Component {
render() {
state = {
gender: this.props.gender || ""
}
toogleGender = (gender)=>{
this.setState({
gender: gender,
})
}
return (
<View style={styles.container}>
<CheckBox
isChecked = {this.state.gender === 'female'}
onClick = {()=> this.toogleGender('female')}
/>
<CheckBox
isChecked = {this.state.gender === 'male'}
onClick = {()=> this.toogleGender('male')}
/>
</View>
);
}
}
componentWillReceiveProps is being deprecated, it would be best to not use it and instead use the new lifecycle methods. https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops