Created
January 2, 2025 16:44
-
-
Save codemile/b909c0efa57718c7700c93818e4d44c5 to your computer and use it in GitHub Desktop.
Combines multiple providers into a single provider.
This file contains hidden or 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 type {FC, PropsWithChildren} from 'react'; | |
export const combineProviders = ( | |
...providers: Array<FC<PropsWithChildren>> | |
): FC<PropsWithChildren> => { | |
return providers.reduce<FC<PropsWithChildren>>( | |
(AccumulatedProviders, CurrentProvider) => { | |
const Component: FC<PropsWithChildren> = ({children}) => ( | |
<AccumulatedProviders> | |
<CurrentProvider>{children}</CurrentProvider> | |
</AccumulatedProviders> | |
); | |
Component.displayName = 'CombinedProviders'; | |
return Component; | |
}, | |
({children}) => <>{children}</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment