Skip to content

Change from undefined to null doesn't run queryFn #6405

Answered by TkDodo
dmitry-seemetrics asked this question in Q&A
Discussion options

You must be logged in to vote

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:

When a query needs more information to uniquely describe its data, you can use an array with a string and any number of serializable objects to describe it. This is useful for:

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

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by dmitry-seemetrics
Comment options

You must be logged in to vote
1 reply
@TkDodo
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