Skip to content
Advertisement

React Hooks useState() with an Array of Object

while I am creating new “Todo” and modifying the fields are no problem my issue is receiving back the child data when I click the “show all objects” button.

Here is a code example to illustrate my issue:

JavaScript

if I click twice on the “add a Todo” button and change one of the field’s values, I will still get the default value

JavaScript

and my purpose would be to get the updated value of the child component.

if you got any idea…

here is the code sandbox link to try and play

thanks in advance

Advertisement

Answer

You can try this and hope it may help you for compoTwo.

Note: You can also set the todo prop value as the initial value of useState.

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