Skip to content
Advertisement

How to replace Array in useState?

I want make program that table content is changed by user’s select. So I put empty array in useState, like this.

JavaScript

And select html code:

JavaScript

When I select option, data will be changed. But I don’t no how to do it with useState. These are data

JavaScript

And my React code:

JavaScript

I tried using map. But I don’t know how to use map, too.

Is there a function or way to change the entire array each time?

Advertisement

Answer

I guess you can handle this action in your handleChange :

JavaScript

If you can’t and you want to use your setStat function I guess you can make something like :

JavaScript

And call this.setStat(e) in your onChange

Advertisement