close

[Solved] React – uncaught TypeError: Cannot read property ‘setState’ of undefined

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error React – uncaught TypeError: Cannot read property ‘setState’ of undefined in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How React – uncaught TypeError: Cannot read property ‘setState’ of undefined Error Occurs?

Today I get the following error React – uncaught TypeError: Cannot read property ‘setState’ of undefined in javascript.

How To Solve React – uncaught TypeError: Cannot read property ‘setState’ of undefined Error ?

  1. How To Solve React – uncaught TypeError: Cannot read property 'setState' of undefined Error ?

    To Solve React – uncaught TypeError: Cannot read property 'setState' of undefined Error This is due to this.delta not being bound to this.
    In order to bind set this.delta = this.delta.bind(this) in the constructor:

  2. React – uncaught TypeError: Cannot read property 'setState' of undefined

    To Solve React – uncaught TypeError: Cannot read property 'setState' of undefined Error This is due to this.delta not being bound to this.
    In order to bind set this.delta = this.delta.bind(this) in the constructor:

Solution 1

This is due to this.delta not being bound to this.

In order to bind set this.delta = this.delta.bind(this) in the constructor:

constructor(props) {
    super(props);

    this.state = {
        count : 1
    };

    this.delta = this.delta.bind(this);
}

Currently, you are calling bind. But bind returns a bound function. You need to set the function to its bound value.

Solution 2

You can also use:

<button onClick={()=>this.delta()}>+</button>

Or:

<button onClick={event=>this.delta(event)}>+</button>

If you are passing some params..

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment