Is there any way to compare the new data with the previous data with useQuery #1890
-
I have a dictionary of booleans I request which lets me know if some rather expensive workflows have been updated.
I use a query to fetch this dictionary but I only want to perform an action if one of these flags has changed from the previous time I've called |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
no, it's not supported currently. It is usually enough to depend on referential identity when running an effect or so. If your list of flags is deterministic, you can do:
Otherwise, you'd need to keep track of the previous one yourselves. There is the usePrevious hook which does that via a ref, or, you can just drag the previous result along in your fetchFn, something like:
I realise that this is a bit of boilerplate, but it basically means getting the data from the cache before doing the "next" fetch and keeping it around. |
Beta Was this translation helpful? Give feedback.
no, it's not supported currently. It is usually enough to depend on referential identity when running an effect or so. If your list of flags is deterministic, you can do:
Otherwise, you'd need to keep track of the previous one yourselves. There is the usePrevious hook which does that via a ref, or, you can just drag the previous result along in your fetchFn, something like: