Skip to content

Instantly share code, notes, and snippets.

@janek26
Last active November 7, 2019 20:37
Show Gist options
  • Save janek26/fe376ac5c6c1ad9cab3146a3aa1fbca9 to your computer and use it in GitHub Desktop.
Save janek26/fe376ac5c6c1ad9cab3146a3aa1fbca9 to your computer and use it in GitHub Desktop.
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