Skip to content
Advertisement

React How to re render map function on change of variabel?

Here is an excerpt which should show my problem. In my project I do something with the grid and now I want to reset it, but I dont know how it works because if I change the grid variable, the .map() function doesnt re render. I hope you understand my problem and you can help me.

That is my code:

JavaScript

Its the same code like here.

Thanks a lot!

Advertisement

Answer

You should use useState hook for that.

JavaScript

then if you want to assign a new value to the grid and cause a rerender you do it like this (inside your App component):

JavaScript
Advertisement