feat: providers combiner
This commit is contained in:
25
src/utils/combineProviders.tsx
Normal file
25
src/utils/combineProviders.tsx
Normal file
@ -0,0 +1,25 @@
|
||||
import { ElementType, PropsWithChildren } from "react";
|
||||
|
||||
type ProvidersType = [ElementType, Record<string, unknown>] | [ElementType];
|
||||
|
||||
export const combineProviders = (
|
||||
...componentsWithProps: Array<ProvidersType>
|
||||
): ElementType => {
|
||||
const getInitial = ({ children }: PropsWithChildren) => children;
|
||||
|
||||
return componentsWithProps.reduce(
|
||||
(
|
||||
AccumulatedComponents: ElementType,
|
||||
[Provider, props = {}]: ProvidersType
|
||||
) => {
|
||||
return ({ children }: PropsWithChildren) => {
|
||||
return (
|
||||
<AccumulatedComponents>
|
||||
<Provider {...props}>{children}</Provider>
|
||||
</AccumulatedComponents>
|
||||
);
|
||||
};
|
||||
},
|
||||
getInitial
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user