Skip to content

Instantly share code, notes, and snippets.

@trujic1000
Created May 1, 2019 17:01
Show Gist options
  • Save trujic1000/9d9eb9b69ff63a8d127b0b5314c7207e to your computer and use it in GitHub Desktop.
Save trujic1000/9d9eb9b69ff63a8d127b0b5314c7207e to your computer and use it in GitHub Desktop.
import React from 'react';
import { Provider1, Provider2, Provider3 } from './';
function ProviderComposer({ contexts, children }) {
return contexts.reduceRight(
// kids = accumulator, parent = currentValue
(kids, parent) =>
React.cloneElement(parent, {
children: kids
}),
// initialValue for kids
children
);
}
function StateProvider({ children }) {
return (
<ProviderComposer
contexts={[<Provider1 />, <Provider2 />, <Provider3 />]}
>
{children}
</ProviderComposer>
);
}
export { StateProvider };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment