discord-questions.trpc.io/m/1304660574080204913

Preview meta tags from the discord-questions.trpc.io website.

Linked Hostnames

4

Thumbnail

Search Engine Appearance

Google

https://discord-questions.trpc.io/m/1304660574080204913

How can I automatically use react's cache with tRPC on server side? - tRPC

I have this in my repo: ```ts import { cache } from "react"; import { headers } from "next/headers"; import { createCaller, createTRPCContext } from "@kdx/api"; import { auth } from "@kdx/auth"; /** * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when * handling a tRPC call from a React Server Component. */ const createContext = cache(async () => { const heads = new Headers(headers()); heads.set("x-trpc-source", "rsc"); return createTRPCContext({ auth: await auth(), headers: heads, }); }); export const api = createCaller(createContext); ``` But, now I need to understand, how should I export the actual functions from the api caller so they are all cached with react's cache? I of course could do something like this ```ts export const uglyGetNotifications = cache(api.user.getNotifications); ``` But I would prefer if I could get an instance of api where all of my endpoints will be using the cache automatically. something like ```ts const notifs = await apiCached.user.getNotifications(); ```



Bing

How can I automatically use react's cache with tRPC on server side? - tRPC

https://discord-questions.trpc.io/m/1304660574080204913

I have this in my repo: ```ts import { cache } from "react"; import { headers } from "next/headers"; import { createCaller, createTRPCContext } from "@kdx/api"; import { auth } from "@kdx/auth"; /** * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when * handling a tRPC call from a React Server Component. */ const createContext = cache(async () => { const heads = new Headers(headers()); heads.set("x-trpc-source", "rsc"); return createTRPCContext({ auth: await auth(), headers: heads, }); }); export const api = createCaller(createContext); ``` But, now I need to understand, how should I export the actual functions from the api caller so they are all cached with react's cache? I of course could do something like this ```ts export const uglyGetNotifications = cache(api.user.getNotifications); ``` But I would prefer if I could get an instance of api where all of my endpoints will be using the cache automatically. something like ```ts const notifs = await apiCached.user.getNotifications(); ```



DuckDuckGo

https://discord-questions.trpc.io/m/1304660574080204913

How can I automatically use react's cache with tRPC on server side? - tRPC

I have this in my repo: ```ts import { cache } from "react"; import { headers } from "next/headers"; import { createCaller, createTRPCContext } from "@kdx/api"; import { auth } from "@kdx/auth"; /** * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when * handling a tRPC call from a React Server Component. */ const createContext = cache(async () => { const heads = new Headers(headers()); heads.set("x-trpc-source", "rsc"); return createTRPCContext({ auth: await auth(), headers: heads, }); }); export const api = createCaller(createContext); ``` But, now I need to understand, how should I export the actual functions from the api caller so they are all cached with react's cache? I of course could do something like this ```ts export const uglyGetNotifications = cache(api.user.getNotifications); ``` But I would prefer if I could get an instance of api where all of my endpoints will be using the cache automatically. something like ```ts const notifs = await apiCached.user.getNotifications(); ```

  • General Meta Tags

    6
    • title
      How can I automatically use react's cache with tRPC on server side? - tRPC
    • charset
      utf-8
    • viewport
      width=device-width, initial-scale=1
    • next-size-adjust
    • description
      I have this in my repo: ```ts import { cache } from "react"; import { headers } from "next/headers"; import { createCaller, createTRPCContext } from "@kdx/api"; import { auth } from "@kdx/auth"; /** * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when * handling a tRPC call from a React Server Component. */ const createContext = cache(async () => { const heads = new Headers(headers()); heads.set("x-trpc-source", "rsc"); return createTRPCContext({ auth: await auth(), headers: heads, }); }); export const api = createCaller(createContext); ``` But, now I need to understand, how should I export the actual functions from the api caller so they are all cached with react's cache? I of course could do something like this ```ts export const uglyGetNotifications = cache(api.user.getNotifications); ``` But I would prefer if I could get an instance of api where all of my endpoints will be using the cache automatically. something like ```ts const notifs = await apiCached.user.getNotifications(); ```
  • Open Graph Meta Tags

    3
    • og:title
      How can I automatically use react's cache with tRPC on server side? - tRPC
    • og:description
      I have this in my repo: ```ts import { cache } from "react"; import { headers } from "next/headers"; import { createCaller, createTRPCContext } from "@kdx/api"; import { auth } from "@kdx/auth"; /** * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when * handling a tRPC call from a React Server Component. */ const createContext = cache(async () => { const heads = new Headers(headers()); heads.set("x-trpc-source", "rsc"); return createTRPCContext({ auth: await auth(), headers: heads, }); }); export const api = createCaller(createContext); ``` But, now I need to understand, how should I export the actual functions from the api caller so they are all cached with react's cache? I of course could do something like this ```ts export const uglyGetNotifications = cache(api.user.getNotifications); ``` But I would prefer if I could get an instance of api where all of my endpoints will be using the cache automatically. something like ```ts const notifs = await apiCached.user.getNotifications(); ```
    • og:image
      https://discord-questions.trpc.io/og/post?id=1304660574080204913
  • Twitter Meta Tags

    4
    • twitter:card
      summary_large_image
    • twitter:title
      How can I automatically use react's cache with tRPC on server side? - tRPC
    • twitter:description
      I have this in my repo: ```ts import { cache } from "react"; import { headers } from "next/headers"; import { createCaller, createTRPCContext } from "@kdx/api"; import { auth } from "@kdx/auth"; /** * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when * handling a tRPC call from a React Server Component. */ const createContext = cache(async () => { const heads = new Headers(headers()); heads.set("x-trpc-source", "rsc"); return createTRPCContext({ auth: await auth(), headers: heads, }); }); export const api = createCaller(createContext); ``` But, now I need to understand, how should I export the actual functions from the api caller so they are all cached with react's cache? I of course could do something like this ```ts export const uglyGetNotifications = cache(api.user.getNotifications); ``` But I would prefer if I could get an instance of api where all of my endpoints will be using the cache automatically. something like ```ts const notifs = await apiCached.user.getNotifications(); ```
    • twitter:image
      https://discord-questions.trpc.io/og/post?id=1304660574080204913
  • Link Tags

    8
    • canonical
      https://discord-questions.trpc.io/m/1304660574080204913
    • icon
      https://cdn.answeroverflow.com/867764511159091230/6af104c7f0f39a12fcd55bd7bd28928f/icon.png
    • preload
      https://www.answeroverflow.com/_next/static/media/4f05ba3a6752a328-s.p.woff2
    • preload
      https://www.answeroverflow.com/_next/static/media/9cf9c6e84ed13b5e-s.p.woff2
    • preload
      /discord/3.png

Links

6