Skip to content

zodios-react key from useXXX is differ from getKeyByXXX #281

Description

@QzCurious

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

  1. useQuery picks params, queries and use it to produce the queryKey.
  2. The pick function would at least return an empty object even if the obj is undefined
  3. The explicit undefined config of useXXX produce 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpinnedissues that should not be closed by bot

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions