Skip to content

Instantly share code, notes, and snippets.

@ashhitch
Forked from stolinski/providerCompose.js
Created April 30, 2019 12:29
Show Gist options
  • Save ashhitch/77af9ed9f036498ff94f732fdd1d11b2 to your computer and use it in GitHub Desktop.
Save ashhitch/77af9ed9f036498ff94f732fdd1d11b2 to your computer and use it in GitHub Desktop.
ProviderComposer
function ProviderComposer({ contexts, children }) {
return contexts.reduceRight(
(kids, parent) =>
React.cloneElement(parent, {
children: kids,
}),
children
);
}
function ContextProvider({ children }) {
return (
<ProviderComposer
contexts={[<CheckoutProvider />, <LoginProvider />, <AlertProvider />]}
>
{children}
</ProviderComposer>
);
}
export { ContextProvider };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment