Charles Stover
May 16 · 2 min read
setGlobal({
name: 'hello world',
header: {
color: 'red',
size: '2em',
},
apis: {
id1: {
loading: false,
response: null,
},
id2: {
loading: false,
response: null,
},
},
});
/*// Class Component
<Header />
this.global.header.color === 'red';
// Function Component
<Header />
const [ header ] = useGlobal('header');
header.color === 'red';
*/
setGlobal({
name: 'hello world',
});
// A Provider for the Header state:
const HeaderProvider = createProvider({
color: 'red',
size: '2em',
});
// A Provider for API calls:
const APIProvider = createProvider({
id1: {
loading: false,
response: null,
},
id2: {
loading: false,
response: null,
},
});
/*// Class Component
<HeaderProvider>
<Header />
</HeaderProvider>
this.global.color === 'red';
// Function Component
<Header />
const [ color ] = HeaderProvider.useGlobal('color');
*/

    Charles Stover

    Written by

    Senior Full Stack JavaScript Developer / charlesstover.com

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade