Skip to content
Advertisement

How to update “prevState” in react.js? [closed]

I have got a list of array of objects. I want to update the state. When I click on the 1st item of the array, it’s giving isTrue: false, when I click on the second array of items, isTrue is given as true. I want to get 1st item isTrue:true, when I click on the second array of items that give isTrue: true. How can I do this?

Here is the link

JavaScript

Advertisement

Answer

You need more than one boolean in state to manage all of them. Update your data to be:

JavaScript

Then add a name or id to your lis

JavaScript

Then update your change handler to update the correct data object

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement