Created
April 27, 2019 05:14
-
-
Save glimberger/d262b58093e6b5d9f95bfbc794f9e73f to your computer and use it in GitHub Desktop.
Composes React context providers
This file contains hidden or 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 * as React from 'react' | |
| 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 default ContextProvider |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment