Skip to content

eslint-disable-next-line react-hooks/exhaustive-deps #11038

Answered by przemyslav
Ekeu asked this question in Q&A
Discussion options

You must be logged in to vote

You shouldn't disable eslint rules unless you know what you do :)
Basically you should pass a function to setProducts to skip using products as products value is not reliable and might be stale.
So:

setProducts(previousProducts => [...previousProducts.map(

This way you don't have to use products and add them as a useEffect dependency and you are guaranteed that the value of previousProducts is not stale :)

The error you had was caused by an endless loop of updates. You ran useEffect that was depending on products, then you changed the value of products. useEffect noticed that and run again, changing the value of products, and so on...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Ekeu
Comment options

Answer selected by Ekeu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants