Skip to content
Discussion options

You must be logged in to vote

if you change the searchText, and its part of the queryKey, you don't get a "refetch". You get a new cache entry and a new initial fetch for that Query. Except that you also pass intitialData for that query again, which like I said in option 1, you shouldn't do if you don't want that.

Maybe this explains it better:

const [variables, setVariables] = useState(1)
useQuery({
  queryKey: ['something', variables]
  queryFn: () => fetchSomething(variables),
  initialData: variables === 1 ? myInitialData : undefined
})

if I don't make the extra comparison, I provide initialData to all cache entries, even if the variable isn't the initial value anymore ...

Replies: 1 comment 4 replies

Comment options

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

@TkDodo
Comment options

Answer selected by CapitanRedBeard
@jpmarra
Comment options

@CapitanRedBeard
Comment options

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