Skip to content

Reset the refetchInterval after request #2117

Answered by TkDodo
mgoguery78 asked this question in Q&A
Discussion options

You must be logged in to vote

1/ Is it a good pattern according to my constraints with backend cache ?

I think cancelling queries before writing to the cache is a good practice - all the examples do that with optimistic updates.

2/ Is there a way to "reset" therefetchInterval so that it restarted after my update?

controlling a query can always be done with local state:

const useMyQuery = () => {
  const [refetchInterval, setRefetchInterval] = React.useState(10 * ONE_SECOND)
  return useQuery('key', fetchFn, { refetchInterval, onSuccess: (data) => setRefetchInterval(data.something) }
}

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…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@thomasbertet
Comment options

@mgoguery78
Comment options

@n3ps
Comment options

@TkDodo
Comment options

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