T
TanStack•3y ago
vicious-gold

useEffect for queries?

useEffect doesn't fire when data in a query changes. How can I make this work?
No description
6 Replies
afraid-scarlet
afraid-scarlet•3y ago
Hi 👋 What are you trying to achieve here?
vicious-gold
vicious-goldOP•3y ago
I have config stored in db that is fetched with react query with that config, I calculate some values and display it to the user the problem is: the config might change using a mutation so I'd like to change the values I calculated earlier too
afraid-scarlet
afraid-scarlet•3y ago
That's what query invalidation solves You'd invalidate the query after performing the mutation And anything you're deriving from the query data should automatically update
vicious-gold
vicious-goldOP•3y ago
I think my current problem is that I have a local state that represents the calculated value and I have a function that uses a react query to calculate and set that state so there is no real dependency -> so my state doesnt update on query invalidation Thx for the help!
afraid-scarlet
afraid-scarlet•3y ago
Why do you have a local state value derived from the query cache value? I'd compute this at render by deriving it from the query data personally by the sounds of it Then it all stays synchronised
vicious-gold
vicious-goldOP•3y ago
ye, you're correct

Did you find this page helpful?