Created
May 1, 2019 17:01
-
-
Save trujic1000/9d9eb9b69ff63a8d127b0b5314c7207e 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