Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Providers context does not work with react rtk react api hooks #3399

Closed
MantasSidabras opened this issue Apr 25, 2023 · 2 comments
Closed

Comments

@MantasSidabras
Copy link

I have a use case for multiple redux stores in my app. I've configures 2 stores as described in this article, by providing a React context for each provider.
Then I've created customCreateApi as described in the docs, by passing dispatch with the proper context.

When I attempt to use useGetPokemonByNameQuery in a component I face this error, of Reach could not find react-redux context value;
image

I've recreated the app with Create react app
repo: https://github.com/MantasSidabras/rtk-app
index, where providers are setup: https://github.com/MantasSidabras/rtk-app/blob/main/src/index.tsx
context is defined here:https://github.com/MantasSidabras/rtk-app/blob/main/src/store/appStoreHooks.ts
api: https://github.com/MantasSidabras/rtk-app/blob/main/src/store/exampleApi/example.ts

App will throw the same error even if I use single Provider with context. I've tried several different version of react-redux, no luck.

Although, I can use RTK Query with by dispatching inititate action manually in useEffect, then selecting it with selector from cache, but thats a hassle. Provided this in example app as App2.tsx

@EskiMojo14
Copy link
Collaborator

you need to provide a useStore hook to your api react module too - create it with createStoreHook from react-redux.

@MantasSidabras
Copy link
Author

Did the trick, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants