So I’m working on a Gatsby project and I’m getting this Error: Could not find "store" in the context
error for a page only in the CMS admin preview. The template is using the connect function from react-redux to connect the component to the store and I’m using wrap wrapRootElement
in gatsby-browser and gatsby-ssr files to wrap the app in the Provider, but I’m thinking that this doesn’t translate to the CMS environment. So my solution is to provide a custom template of the page in question that does not use any components that need the redux store to operate. Are my observations correct here?
Hi @bknight and welcome to the community
Your observations seem to be correct, but sharing your repo/code will help confirming it.
You should be able to use redux
in preview templates, but you’ll probably need to wrap them with a provider Redux Fundamentals, Part 5: UI and React | Redux
The main thing to remember is that the CMS is a separate React App that runs completly in the browser, so it won’t have access to your main app redux store nor support any server side rendering functionality of Gatsby.
It has a separate build step as well, done by the Gatsby CMS plugin.
Hopefully that makes sense