\n\n1/ Is it a good pattern according to my constraints with backend cache ?
\n
I think cancelling queries before writing to the cache is a good practice - all the examples do that with optimistic updates.
\n\n\n2/ Is there a way to \"reset\" therefetchInterval so that it restarted after my update?
\n
controlling a query can always be done with local state:
\nconst useMyQuery = () => {\n const [refetchInterval, setRefetchInterval] = React.useState(10 * ONE_SECOND)\n return useQuery('key', fetchFn, { refetchInterval, onSuccess: (data) => setRefetchInterval(data.something) }\n}\n
by setting the refetchInterval to a value depending on the data in onSuccess (0 if you want to turn it off), you'll re-render your component and the queryOptions update accordingly.
","upvoteCount":2,"url":"https://github.com/TanStack/query/discussions/2117#discussioncomment-605443"}}}-
👋 Hello ! I have a project where I trigger a GET query every 10 seconds to retrieve some data, with the To fix that, I used the Thanks a lot for your help ! 🙏
|
Beta Was this translation helpful? Give feedback.
-
I think cancelling queries before writing to the cache is a good practice - all the examples do that with optimistic updates.
controlling a query can always be done with local state:
by setting the refetchInterval to a value depending on the data in onSuccess (0 if you want to turn it off), you'll re-render your component and the queryOptions update accordingly. |
Beta Was this translation helpful? Give feedback.
I think cancelling queries before writing to the cache is a good practice - all the examples do that with optimistic updates.
controlling a query can always be done with local state:
by setting the refetchInterval to a value depending on the data in onSuccess (0 if you want to turn it off), you'll re-render your…