Skip to content

Consuming the react query useQuery hook from third party lib cause error #9129

@shmdhussain

Description

@shmdhussain

Describe the bug

Note: I read this issue #3595 which is about using the useQuery hook from the third party lib.

In that issue @TkDodo mentioned that if the react and react-query version are same , It will work, when I try that it is not working.

Demo

I created one simple demo stackblitz (https://stackblitz.com/~/github.com/shmdhussain/react-query-third-party-lib) using monorepo.

use npm run start to see the demo works,

Reproduce steps:

just click to comp1 (it works correctly) but when you click comp2 it wont work because of the error No QueryClient set, use QueryClientProvider to set one

explanation of my issue

In the demo, I placed my app @mymonorepo/my-appwhich consumes two libs (@mymonorepo/my-lib-1) and (@mymonorepo/my-lib-2) (consider those two as 3rd party libs giving us custom hooks (useFetchIds' which internally uses the useQuery`).

In @mymonorepo/my-lib-1 I just exported hook only and made the react query as external peer deps to be provided by consuming lib which is @mymonorepo/my-app

In @mymonorepo/my-lib-2 I exported/bundled hook along with the react query, in that case when consuming from my app is not working , when I debugged the bundled code of 3rd part lib found that useQuery from the 3rd party lib uses the context from the 3rd party lib rather than from the consuming app, which causes this issue.

By @TkDodo comment in the issue, If i use same version of react and react-query it should work, but not working. Am I missing anything here or any work around to make it work?

Thanks in advance for any help

Expected behavior

It should work from third party hooks.

How often does this bug happen?

None

Screenshots or Videos

Image

Platform

  • All

Tanstack Query adapter

None

TanStack Query version

5.75.5

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions