12 Jul 2017

Import CheckBox value not changing in react-native.

Import CheckBox value not changing in react-native.

Guest Post

Import CheckBox from 'react-native-checkbox'
and i am using it this way
<CheckBox
label='Show Password'
checked={false}
onChange={(checked) => console.log('i am checked')}/>
Trouble i am having is , i am not been able to change it's value.

Solution :

constructor (props) {
super(props)
this.state = {
value:false
}
}
valueChange(value){
if (this.state.value==true) {
this.setState({
value:false
});
}
else{
this.setState({
value:true
});
}
}

<CheckBox
label='Show Password'
checked={this.state.value}
onChange={(checked) => this.valueChange(checked)}/>

================================================

 state = {
checked: false
}

<CheckBox
label='Show Password'
checked={this.state.checked}
onChange={(checked) => this.setState({ checked }) }/>


Users Please post your solution.

No comments:

Post a Comment