TypeError: Cannot read property ‘setState’ of undefined

state= {
users :[
{ name : ‘ram’ , salary :2000 },
{ name : ‘john’ , salary :3000}
]
}
updateUsers( ){
this.setState(
{
users :[
{ name : ‘smith’ , salary :12000 },
{ name : ‘lara’ , salary :3400}
]
}
)
}
<buttononClick={this.updateUsers}>Update Users</button>
But it is show me error :
TypeError: Cannot read property ‘setState’ of undefined
Solution :
Change update user as
updateUsers = () => {
this.setState(
{
users :[
{ name : ‘smith’ , salary :12000 },
{ name : ‘lara’ , salary :3400}
]
}
)
}

Leave a Reply

Your email address will not be published. Required fields are marked *

− 1 = 1