rtk-incubator / rtk-query

Data fetching and caching addon for Redux Toolkit
https://redux-toolkit.js.org/rtk-query/overview
MIT License
626 stars 31 forks source link

could not find react-redux context value; #113

Closed kahirokunn closed 3 years ago

kahirokunn commented 3 years ago

Could not find react-redux context value" inside react-redux. :cry:

markerikson commented 3 years ago

@kahirokunn that's really not enough info for us to offer any help.

Do you actually have a Redux store setup and and a <Provider> around your app, per the instructions?

https://rtk-query-docs.netlify.app/introduction/getting-started/#wrap-your-application-with-the-provider

kahirokunn commented 3 years ago

In my environment, I don't get this error when using useDispatch inside a Provider. However, if I change useDispatch to use hooks obtained from RTK Query such as useGetPokemonByNameQuery in the sample, the error occurs.

kahirokunn commented 3 years ago

I thought that maybe a different react-redux was installed, which resulted in a different context, but that was not the case.

$ ls node_modules/@rtk-incubator/rtk-query/
LICENSE  README.md  dist  package.json  src
kahirokunn commented 3 years ago

I found the cause.

Using the debugger, I found that rtk-query imports react-redux/es. My babel was configured to import react-redux/lib. Therefore, it was referring to a different Context. This was a simple mistake. The following fix fixes it. I apologize for the inconvenience.

"plugins": [
  ["transform-imports", {
    "react-redux": {
-      "transform": "react-redux/lib",
-      "transform": "react-redux/es",
      "preventFullImport": true,
      "skipDefaultConversion": true
    }
  }]
]
markerikson commented 3 years ago

yup, something like that is usually the case :)