Skip to content

Instantly share code, notes, and snippets.

@longfellowone
Forked from trujic1000/state.js
Created May 12, 2019 21:12
Show Gist options
  • Save longfellowone/b8b4b7cd8ca84d5a3e48a57c0972202e to your computer and use it in GitHub Desktop.
Save longfellowone/b8b4b7cd8ca84d5a3e48a57c0972202e 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