Skip to content
Discussion options

You must be logged in to vote

I think an effect that listens to query.isStale is a good approach, as observers are also informed about queries getting stale. To trim down the code a bit, you can use the refetch function returned from useQuery:

const myQuery = useQuery("my query", fetchData, {
  staleTime: TTL,
})
useEffect(() => {
  if( myQuery.isStale ) {
    myQuery.refetch()
  }
}, [myQuery.isStale, myQuery.refetch])

not a super good improvement though, but hidden in a custom hook I think it's not a bad pattern at all.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by ryanoglesby08
Comment options

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

Comment options

You must be logged in to vote
0 replies
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