Skip to content

Instantly share code, notes, and snippets.

@benjick
Created April 16, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjick/404861c8b069ca0be362f2630855ee70 to your computer and use it in GitHub Desktop.
Save benjick/404861c8b069ca0be362f2630855ee70 to your computer and use it in GitHub Desktop.
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