Hi I’ve spent far to much time today trying to figure this out!
I’m rebuilding my site using Gatbsy and learning about all the new bits and pieces I have recently built my site in React which went well. However, my issue seems simple (4 hours ago) I want to pass a state into the react app the access it in two separate components.
But as Gatsby uses this I can’t find any way to pass a state down to components? as soon as I add a constructor outside of const layout it goes bang. Any help would really be appreciated.
const Layout = ({ children }) => (
<StaticQuery
query={graphql`
query SiteTitleQuery {
site {
siteMetadata {
title
}
}
}
`}
render={data => (
<>
<MobileMenu menuOpen={this would be the state}/>
<Header siteTitle={data.site.siteMetadata.title} menuOpen={this would be the state} />
<div
style={{
margin: `0 auto`,
Thanks, unfortunately I have already tried that method and as soon as I added the StaticQuery gatsby rejected it, and didn’t seem to process it. I’ll have another look now and see pop what the error on here.
I have just tried adding it theres something (I imagine something simple) that i’m missing and how to go from StaticQuery to the code. Any help would be really appreciated.
You legend that that got me along the right lines I had to convert it to a class to pass the menu state through a mobile menu and header component but now have that bit working.
Thanks for your help very much appreciated.
Just in case anyone else needs this whilst using Gatbsy here’s my example