Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes posible to check/uncheck from parent component #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PinkiPalacios
Copy link

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
Copy link
Author

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

@TwiggyRJ
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants