Change from undefined to null doesn't run queryFn #6405
-
React-query doesn't run queryFn if queryKey changed from undefined to null or from null to undefined. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Our internal query key hashing is based on If that's an issue for you, you can provide your own The docs say:
but I agree that could be described a bit better. If you want, please file a PR to update the docs? |
Beta Was this translation helpful? Give feedback.
-
@TkDodo I have another issue related to hashing I have an endpoint /messages?maxIndex=number|undefined I am changing this parameter in the key dynamically from And then call query.refetch() it is being re-fetched with the previous value 777 instead of undefined is that expected? |
Beta Was this translation helpful? Give feedback.
Our internal query key hashing is based on
JSON.stringify
, which will yield'[null]'
for both[null]
and[undefined]
.If that's an issue for you, you can provide your own
queryKeyHashFn
. You can also do that globally as a default option.The docs say:
but I agree that could be described a bit better. If you want, please file a PR to update the docs?
https://tanstack.com/query/latest/docs/react/guides/query-keys#query-keys-are-hashed-deterministically