Skip to content
Advertisement

Too many rerednders error by trying to show a FlatList

I am trying to display a flatList of numbers like this : (image of what the flat list would look like) To do that I did an array of objects with a numberName and a key, it’s generating with a loop:

JavaScript

I dont think the problem is in the loop, but react is recalling the loop without showing the component. This makes an infinite loop and I have the too Many rerender error.

Here is what console.log(nums) shows (screenshot of the console)

and here is how i am trying to render the array :

JavaScript

Why do I have the too many rerenders error and how do I fix it ?

Advertisement

Answer

JavaScript

You need to do assignment/state-related stuff inside useEffect hook.

Advertisement