From c80992aa1c9f05f8ce9dde64c8654d8bdfa27034 Mon Sep 17 00:00:00 2001 From: Alex Johansson Date: Thu, 30 Sep 2021 13:28:30 +0100 Subject: [PATCH] move `withTRPC`-HOC to `_app.tsx` (#822) --- lib/app-providers.tsx | 36 +----------------------------------- pages/_app.tsx | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/app-providers.tsx b/lib/app-providers.tsx index 49ca1de46f..b748f69269 100644 --- a/lib/app-providers.tsx +++ b/lib/app-providers.tsx @@ -1,7 +1,4 @@ import { IdProvider } from "@radix-ui/react-id"; -import { httpBatchLink } from "@trpc/client/links/httpBatchLink"; -import { loggerLink } from "@trpc/client/links/loggerLink"; -import { withTRPC } from "@trpc/next"; import { Provider } from "next-auth/client"; import { AppProps } from "next/dist/shared/lib/router/router"; import React from "react"; @@ -22,35 +19,4 @@ const AppProviders = (props: AppProps) => { ); }; -export default withTRPC({ - config() { - /** - * If you want to use SSR, you need to use the server's full URL - * @link https://trpc.io/docs/ssr - */ - return { - /** - * @link https://trpc.io/docs/links - */ - links: [ - // adds pretty logs to your console in development and logs errors in production - loggerLink({ - enabled: (opts) => - process.env.NODE_ENV === "development" || - (opts.direction === "down" && opts.result instanceof Error), - }), - httpBatchLink({ - url: `/api/trpc`, - }), - ], - /** - * @link https://react-query.tanstack.com/reference/QueryClient - */ - // queryClientConfig: { defaultOptions: { queries: { staleTime: 6000 } } }, - }; - }, - /** - * @link https://trpc.io/docs/ssr - */ - ssr: false, -})(AppProviders); +export default AppProviders; diff --git a/pages/_app.tsx b/pages/_app.tsx index 88c67c5297..b0cdffcfc6 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,3 +1,6 @@ +import { httpBatchLink } from "@trpc/client/links/httpBatchLink"; +import { loggerLink } from "@trpc/client/links/loggerLink"; +import { withTRPC } from "@trpc/next"; import { appWithTranslation } from "next-i18next"; import { DefaultSeo } from "next-seo"; import type { AppProps as NextAppProps } from "next/app"; @@ -23,4 +26,35 @@ function MyApp(props: AppProps) { ); } -export default appWithTranslation(MyApp); +export default withTRPC({ + config() { + /** + * If you want to use SSR, you need to use the server's full URL + * @link https://trpc.io/docs/ssr + */ + return { + /** + * @link https://trpc.io/docs/links + */ + links: [ + // adds pretty logs to your console in development and logs errors in production + loggerLink({ + enabled: (opts) => + process.env.NODE_ENV === "development" || + (opts.direction === "down" && opts.result instanceof Error), + }), + httpBatchLink({ + url: `/api/trpc`, + }), + ], + /** + * @link https://react-query.tanstack.com/reference/QueryClient + */ + // queryClientConfig: { defaultOptions: { queries: { staleTime: 6000 } } }, + }; + }, + /** + * @link https://trpc.io/docs/ssr + */ + ssr: false, +})(appWithTranslation(MyApp));