feat: providers combiner
This commit is contained in:
@ -15,6 +15,7 @@ import {
|
||||
getBoardsOptions,
|
||||
getProjectsOptions,
|
||||
} from "@/lib/client/@tanstack/react-query.gen";
|
||||
import { combineProviders } from "@/utils/combineProviders";
|
||||
import { DealsContextProvider } from "./contexts/DealsContext";
|
||||
|
||||
async function prefetchData() {
|
||||
@ -34,11 +35,15 @@ async function prefetchData() {
|
||||
export default async function DealsPage() {
|
||||
const queryClient = await prefetchData();
|
||||
|
||||
const Providers = combineProviders(
|
||||
[HydrationBoundary, { state: dehydrate(queryClient) }],
|
||||
[ProjectsContextProvider],
|
||||
[BoardsContextProvider],
|
||||
[StatusesContextProvider]
|
||||
);
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<ProjectsContextProvider>
|
||||
<BoardsContextProvider>
|
||||
<StatusesContextProvider>
|
||||
<Providers>
|
||||
<PageContainer>
|
||||
<PageBlock className={"mobile-margin-height"}>
|
||||
<Header />
|
||||
@ -48,9 +53,6 @@ export default async function DealsPage() {
|
||||
</DealsContextProvider>
|
||||
</PageBlock>
|
||||
</PageContainer>
|
||||
</StatusesContextProvider>
|
||||
</BoardsContextProvider>
|
||||
</ProjectsContextProvider>
|
||||
</HydrationBoundary>
|
||||
</Providers>
|
||||
);
|
||||
}
|
||||
|
||||
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