'React Native Can't call setState on a component that is not yet mounted
I keep getting this error in React Native and I have not found a solution yet after a few hours.
Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to
this.statedirectly or define astate = {};class property with the desired state in the myEnabled component.
constructor(props){
super(props);
this.state = { enabled: true };
this.setEnabled = this.setEnabled.bind(this);
}
setEnabled(value){
this.setState({ enabled: value });
}
getState(){
return this.state.enabled;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
