Question:I’m building a to-do list and I want each list item to have a number, starting from 1. I’m using the useState hook on the counter but I can’t figure out how to add new items to the array every time I click on a button. I haven’t coded in months and I’m really rusty.
Answer:This is really bad practice:
What you want to do is use the
keyattribute to the individual child values according to the official React documentation as follows
Also, change your variable names to something more meaningful. I’d suggest changing
Your final code should look like this:
If you have better answer, please add a comment about this, thank you!