How to initialize redux store with data from Gatsby page query?
See original GitHub issueSummary
How to initialize redux store with data from a Gatsby page query?
Is there a way to use the wrapRootElement
function on ssr?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:25 (13 by maintainers)
Top Results From Across the Web
Using Gatsby + Redux While Preserving Site Performance
Create a custom Redux store with reducers and initial state, ... Commons, libraries used on every Gatsby page, commons-[hash].js.
Read more >Gatsby: The ultimate guide with examples - LogRocket Blog
This tutorial covers everything you'll ever need to know about Gatsby, including code demos and comparisons to React and Next.js.
Read more >Add data to Gatsby's Data layer using sourceNodes
In this post i'm going to demonstrate how to source data from a NASA API and inject the response into Gatsby's GraphQL layer...
Read more >Renovate Bot Package Diff
utils/page-data\"\nimport {\n structureWebpackErrors,\n ... any>\n): Promise<void> {\n // global gatsby object to use without store\n global.
Read more >Executing async code on update of state with react-hooks
then((o) => { const { orders: fetchedOrders } = o. ... data; const allOrders = orders.concat(fetchedOrders); setOrders(allOrders); setPage(page + 1); setPagesSeen ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is how I handle that in one of the projects I’m working on:
It doesn’t really do a lot at the moment, but the concept is there.
It’s also possible to use hooks if you wrap it in another React component
@Js-Brecht I’m using mobx-state-tree for storing data, and it contains some product data that doesn’t change very often, so I want to get those data ready in the build time. Fetching those data is written in mobx-state-tree action, and it is REST API instead of graphQL.
I implemented wrapRootElement in gatsby-ssr.js and gatsby-browser.js. wrapRootElement is the same function that creates a store and wrapping the element with context provider. According to some tutorial.
I also need to createPage in gatsby-node.js according to using-gatsby-without-graphql, but all the data fetching is currently done in the store, so in order to fetch the data, I need to somehow access the store that was created in the gatsby-ssr.js or gatsby-browser.js.
How am I supposed to do that? Or I should use a different approach?
Your answer is the closest approach, but you are using graphQL, so I don’t know what I should do with my stuff.
I also posted my questions here.