Skip to content

Instantly share code, notes, and snippets.

@m5r
Last active March 25, 2022 06:20
Show Gist options
  • Save m5r/795b8575e9bd89e66f668c39853d47fc to your computer and use it in GitHub Desktop.
Save m5r/795b8575e9bd89e66f668c39853d47fc to your computer and use it in GitHub Desktop.
import type { FunctionComponent } from "react";
export const combineProviders = (providers: FunctionComponent[]) => providers.reduce(
(Combined, Provider) => ({ children }) => (
<Combined>
<Provider>{children}</Provider>
</Combined>
),
);
import { BrowserRouter } from "react-router-dom";
import { RecoilRoot } from "recoil";
import { ApolloProvider } from "@apollo/client";
import { combineProviders } from "./combine-provider";
const Providers = combineProviders([
BrowserRouter,
RecoilRoot,
ApolloProvider,
]);
function Root() {
return (
<Providers>
<App />
</Providers>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment