Skip to content
Advertisement

Error: Too many re-renders. because i changed setState

error: Too many re-renders.
explaining code: (
iam maping array of object – in that mapping funtion i maked new array of objects( raiting = [..rating, {}] ) then set useState state to be that array of objects ( setRatingFinal([...rating]) ) and then final i display that – but iam getting error.
)
Can somebody write me answer for this, if its posible to write code in answer. Thanks.

JavaScript

the movies is array of 3021 objects – example of one object in that array –

JavaScript

i tryed without var rating just with ratingFinal, but and that dont work- like this:

JavaScript

Advertisement

Answer

make timeout and move setRatingFinal([...rating]) in timeout minimum 100ms, and you must make one objec with value because in first render it will not show (it can’t read property of undefined)

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