-
-
Save longfellowone/b8b4b7cd8ca84d5a3e48a57c0972202e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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