Created
July 6, 2023 10:00
-
-
Save guillermodlpa/5293d53238c995f62dcd2c75386589b2 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
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