Server Side Rendering components that uses React Context #28378
Unanswered
SaurabhChouhan
asked this question in
Help
Replies: 1 comment
-
Have you tried this: https://www.gatsbyjs.com/blog/2019-01-31-using-react-context-api-with-gatsby/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I used context API to pass data to my top level page components. I get data from API and then set data in context which then triggers rendering pages. A sample component looks like this (only adding code enough to understand issue)
As site loads it fetches data (countries) from graphql API, set it in context and then this sample component shows list of countries.
What I am trying to do is to somehow set this data in context in such a way that when I use above component as a template while creating page using createPages action, the data added to context is available in this component and used to generate HTML during build. But console added in component shows context as undefined. To pass context I tried creating a wrapRootElement passing countries as below, but still context is shows as undefined while building. So my question is that is it possible to populate context during gatsby build lifecycle using any mechanism so that I can set appropriate data and use same components to build SEO htmls in gatsby build.
Beta Was this translation helpful? Give feedback.
All reactions