const Providers = ({ children }) => (
<ProviderComposer
providers={[
provider(GoogleTagManager),
provider(StylesProvider, { injectFirst: true }),
provider(MUIThemeProvider, { theme: theme }),
]}
>
{children}
</ProviderComposer>
);
Last active
December 31, 2022 16:03
-
-
Save brunos3d/30fdcbd9b006a9021a81dd3c07debf44 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 { ComponentProps, JSXElementConstructor } from 'react'; | |
export const provider = <C extends JSXElementConstructor<unknown>>( | |
provider: C, | |
props: Partial<ComponentProps<C>> = {} | |
) => [provider, props]; | |
export const ProviderComposer = ({ providers, children }) => { | |
for (let i = providers.length - 1; i >= 0; --i) { | |
const [Provider, props] = providers[i]; | |
children = <Provider {...props}>{children}</Provider>; | |
} | |
return children; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment