You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ok, so can we break it into two different contexts?
In layouts?
Just bear in mind that in Gatsby v2 layouts is being removed, I can't remember the structure now as I'm currently in react-static land 🙃
Anyway I think the general idea is that you split your contexts by grouping them so:
importReactfrom'react'// Context is made up of two things// Provider - Single as close to top level as possible// Consumer - Multiple have multiple consumersexportconstPresentationalContext=React.createContext()exportclassPresentationalProviderextendsReact.Component{state={item1: 1,item2: 2}// add function herefunctionHere=()=>{this.setState({item1: 2,item2: 3})}render(){return(<PresentationalContext.Providervalue={{
...this.state,functionHere: this.functionHere}}>{this.props.children}</PresentationalContext.Provider>)}}
and the same for the app data, then when you need the data you wrap the consumer around the main component of where you want to use the data.
Additional resources:
#246 (comment)
The text was updated successfully, but these errors were encountered: