react-native-check-box icon indicating copy to clipboard operation
react-native-check-box copied to clipboard

makes posible to check/uncheck from parent component

Open PinkiPalacios opened this issue 8 years ago • 2 comments

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[ ]

PinkiPalacios avatar Apr 03 '18 22:04 PinkiPalacios

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

PinkiPalacios avatar Apr 03 '18 22:04 PinkiPalacios

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

TwiggyRJ avatar Jun 12 '18 13:06 TwiggyRJ