@trpc-swr/ssr
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

@trpc-swr/ssr

tRPC-ified SWR hooks

Framework agnostic SSR for trpc-swr.

Documentation: https://trpc-swr.vercel.app/server-side/next-13-appdir

Usage

Define a helper function to create a new trpc ssr instance for each request.

In server/ssr.ts

import { createProxySSGHelpers } from "@trpc-swr/ssr";
import { appRouter } from "server/appRouter";

export const createSSR = () => {
  return createProxySSGHelpers({
    router: appRouter,
    ctx: {},
  });
};

In a page

import { createSSR } from "<trpc-ssr-location>";

const getData = () => {
  const rsc = createSSR();

  return rsc.home.getVersion.fetch();
};

export default async function HomePage() {
  const version = await getData();

  return <div>{version}</div>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @trpc-swr/ssr

Weekly Downloads

401

Version

2.0.1

License

MIT

Unpacked Size

28.9 kB

Total Files

8

Last publish

Collaborators

  • chiefkoshi