feat: providers combiner

This commit is contained in:
2025-08-26 16:53:47 +04:00
parent 31bd888357
commit 4a758e4cf0
2 changed files with 44 additions and 17 deletions

View 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
);
};