Created
April 16, 2019 13:17
-
-
Save benjick/404861c8b069ca0be362f2630855ee70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Site from './models/Site'; | |
export const Context = React.createContext(); | |
export function useSite() { | |
return React.useContext(Context); | |
} | |
export function SiteWrapper(props) { | |
const [context, setContext] = React.useState(null); | |
React.useEffect(() => { | |
const site = Site.create({id: props.match.params.siteId}); | |
site.load(); | |
setContext(site); | |
}, []); | |
if (!context) { | |
return null; | |
} | |
console.log('context', context); | |
return <Context.Provider value={context}>{props.children}</Context.Provider>; | |
} | |
// import {Provider, Site, useSite} from '../store/site'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment