Answers for "this.state returns undefined react native"

0

this.state returns undefined react native

The issue that in the first example toggle() is not bound to the correct this.

You can either bind it in the constructor:

constructor(props) {
    super(props);
    this.toggle = this.toggle.bind(this);
    ...
    
Or use an instance function (OK under some circumstances):

toggle = () => {
    ...
}
Posted by: Guest on September-08-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language