Skip to content

Commit

Permalink
move withTRPC-HOC to _app.tsx (calcom#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Sep 30, 2021
1 parent 8ac56fb commit c80992a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
36 changes: 1 addition & 35 deletions lib/app-providers.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
36 changes: 35 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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));

0 comments on commit c80992a

Please sign in to comment.