Last active
November 7, 2019 20:37
-
-
Save janek26/fe376ac5c6c1ad9cab3146a3aa1fbca9 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, { FC, ComponentType } from 'react'; | |
interface Props { | |
Providers: { component: ComponentType<any>; props?: any }[]; | |
} | |
export const ComposeProviders: FC<Props> = ({ Providers, children }) => | |
Providers.reverse().reduce((acc, Provider) => { | |
return ( | |
<Provider.component {...(Provider.props || {})}> | |
{acc} | |
</Provider.component> | |
); | |
}, <>{children}</>); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment