Getting state error: undefined is not an object in a function

There is a quite common issue with developers who just starting to use ReactJs. The junior and intermediate developers my team always have the issue undefined is not an object when they use this.state.[statement] in function. The problem is in Javascript in general, you need to pass the context of the App to use this keyword in the function. Most of the cases which cause the problem is developer don’t use the constructor way to declare the function which is this.function = this.function.bind(this)

Posted by justinpham

Leave a Reply