Does the queryFn need to have a stable reference?
When providing useQuery with a queryFn, will the query fire each time it receives a new queryFn reference? E.g., when defining a function inline:
3 Replies
dependent-tanOP•7d ago
From local testing, it seems there's absolutely no effect from changing the function between renders, only the query keys have an effect. Is that the intended behavior?
ambitious-aqua•7d ago
Yes, the
queryFn is only to be ran when queryKey or other things change. Not sure if this works (even if it does, it is a scuffed way of doing it, as it breaks other integrations like persist) you might be able to add the queryFn reference to the queryKey
you could also call queryClient.invalidateQueries when you change your queryFn so they rerun
the only time I know of that a query gets ran on a callback reference change is for the select optionrare-sapphire•6d ago
no.