zodios-react key from useXXX is differ from getKeyByXXX
The Bug
Here is a reproduction CodeSandbox.
The bug is caused by explicitly passing undefined as config to a useXXX. But not on getKeyByXXX
Workaround
Explicitly pass {} to getKeyByXXX as config.
The workaround would NOT work if I try to getKeyByXXX on a immutable query. It's because useImmutableQuery additionally append body to its queryKey.
The Root Cause
For useXXX
-
useQuery picks
params,queriesand use it to produce the queryKey. - The
pickfunction would at least return an empty object even if theobjisundefined - The explicit
undefinedconfig ofuseXXXproduce a{}in its queryKey
For getKeyByXXX
It essentially do the same as useXXX. But it checks if config is passed and then make it part of queryKey.
Possible Solution
At first, I believe there is a bug on pick implementation. If the obj is undefined, it should return undefined, too.
Fix the Mismatch Behavior between useXXX and getKeyByXXX.
Both these two function needs to derive queryKey from config. So either copy paste the code one another . Or an helper method might be cleaner.
Hope the context is enough for you to fix this. I'm sorry that currently I don't have time to do the PR.
Thank you for taking the time to report this issue and also to create a reproductible example. This will be fixed today as it should be an easy fix. to evoid issues in the future, i'll share the code between the two.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sorry for delay, not as easy as i thought.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is there any update on this? Really liking the library so far but this "breaks" my hydration setup.
I investigated it a bit and it seems like in the getKeyByX methods there is a check whether config is undefined or not. But useQuery does not have that check. Could this be the issue?