0

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.state directly or define a state = {}; 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;
    }
tdgog
  • 1
  • 1
  • Does this answer your question? [Can't call setState on a component that is not yet mounted](https://stackoverflow.com/questions/50162522/cant-call-setstate-on-a-component-that-is-not-yet-mounted) – Giovanni Londero Jan 27 '22 at 11:35
  • you should learn about react's lifecycle methods; [React lifecycle](https://en.reactjs.org/docs/react-component.html) – Cem Kocagöz Jan 27 '22 at 19:57

0 Answers0