Skip to content

Instantly share code, notes, and snippets.

@guillermodlpa
Created July 6, 2023 10:00
Show Gist options
  • Save guillermodlpa/5293d53238c995f62dcd2c75386589b2 to your computer and use it in GitHub Desktop.
Save guillermodlpa/5293d53238c995f62dcd2c75386589b2 to your computer and use it in GitHub Desktop.
export default function composeContextProviders(providers: React.ElementType[]) {
return providers.reduce(
(Prev, Curr) =>
function ComposedProviderWrapper({ children }) {
return (
<Prev>
<Curr>{children}</Curr>
</Prev>
);
},
);
}
// usage example:
const ComponentContextProviders = composeContextProviders([
NavDrawerProvider,
AskHelpDialogContextProvider,
]);
function App() {
return (
<ComponentContextProviders>
{/* ... */}
</ComponentContextProviders>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment