Skip to content
Advertisement

useState not working with Array of Objects

So I am working with React Hooks and with an array of names which will have buttons. On clicking those buttons the corresponding name would disappear. But the array is not updating at all.

JavaScript

Please advise what can be done, I’m a newbie in React. Thank you!

Advertisement

Answer

You are using your data variable which never changes instead of using the “people” variable which is your “react state”.

Just use “people” in your render.

May I advise you to have a look here : https://reactjs.org/docs/hooks-reference.html#usestate You will find several examples

JavaScript
Advertisement