Advanced tRPC - Callers, functions, and gSSP

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024
  • 🚨 createSSGHelpers has been renamed to createServerSideHelpers 🚨
    Repo for this video: github.com/c-e...
    If you want to use schema in the frontend, they cannot be imported from the same file as things that run specifically in the backend. One solution would be to put them into a `procedureName.schema.ts` or similar file.
    tRPC:
    trpc.io/docs
    Create T3 App:
    create.t3.gg/
    Find me:
    / ccccjjjjeeee
    github.com/c-e...

Комментарии • 43

  • @kubakazimierczak6646
    @kubakazimierczak6646 Год назад +2

    Thanks Chris for explaining all of this. Your video touches on many topics, but lacks timestamps, so I wrote them down:
    0:48 - Separate common logic into it's own functions
    3:14 - How to structure your project
    How to call tRPC procedures from getServerSideProps:
    5:05 - createCaller()
    5:33 - just call an extracted function (see 0:48)
    tRCP calls with dynamic inputs (ex.: from query string):
    6:15 - with initialData
    7:35 - with createServerSideHelpers + dehydrate (aka createProxySSGHelpers in older versions)

  • @filipniklas
    @filipniklas Год назад

    Super helpful! Reading docs and posts is one thing but for those who are new to tRPC and web dev in general, having someone to walk you through the logic and code really helps the understanding. Thank you for making this!

  • @Manmanolo115
    @Manmanolo115 Год назад +1

    Looking forward to the testing video! I got stuck setting vitest, specifically on integrating env vars.

  • @TomDoesTech
    @TomDoesTech Год назад +3

    As soon as I heard that question, I though "omg please don't show people how to do that". But of course, you know better than that. Great video!
    Edit: Also, great thumbnail

  • @xXFlameSwordsmanXx
    @xXFlameSwordsmanXx Год назад

    Waiting for that testing T3/TRPC video!!

  • @gabrielbianchi2246
    @gabrielbianchi2246 Год назад

    Legendary video. Thank you. Please keep creating more stuff like this

  • @Amazing.U
    @Amazing.U Год назад

    You are amazing! Thanks to you, now I can statically generate all the dynamic routes that have fixed content! BTW, I did land on that page at some point! 😂

  • @SonAyoD
    @SonAyoD Год назад +1

    great video! more trpc stuff please

  • @pmioduszewski
    @pmioduszewski Год назад

    damn if I knew this video earlier... great explanation thx!

  • @oscartbeaumont
    @oscartbeaumont Год назад +1

    Great videos!

  • @reqtified
    @reqtified Год назад

    Is it possible to do a DB check in prisma with the middleware, I basically need to check if a user is authed and also DOES exist in the database

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад

      yes, trpc middleware runs on the server so you can do all the normal server stuff.
      next.js middleware is a different thing and a bit more complicated in terms of what you can and can't do

  • @mendylanda125
    @mendylanda125 Год назад

    Great content! ❤
    Thank you 🙏

  • @felix20111128
    @felix20111128 Год назад

    Thanks for making this video, it's super helpful! I did some tests locally, with createServerSideHelpers, it indeed prefetched the data on the client. However, after checking the network requests, I noticed that there's still a request sent to the trpc api route on the backend after the page is loaded on the client, is this expected? Thanks!

    • @felix20111128
      @felix20111128 Год назад

      Nvm, it turns out that I forgot to set staleTime in useQuery :)

  • @infisspablo8602
    @infisspablo8602 Год назад

    nice!

  • @juliusmarminge
    @juliusmarminge Год назад +1

    Niceeee

  • @diegocardenas4522
    @diegocardenas4522 Год назад

    Why should we use SSG helpers vs SSR=true option in TRPC ?

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад +1

      There are some apps/situations where just enabling `ssr` will get the job done, but:
      - ssr: true is a global setting, which you might not want
      - there are issues when you use `ssr: true` WITH gSSP (which you might need in order to call other stuff on the server), see the note here: trpc.io/docs/ssr
      maybe i'll make a separate video about ssr and ssg strategies in the future.

    • @diegocardenas4522
      @diegocardenas4522 Год назад

      @@ccccjjjjeeee a video like that would be very much appreciated, I'm trying to optimize my app at work and honestly I'm quite new to both ssr and trpc :)

    • @facundoflores4763
      @facundoflores4763 Год назад +1

      @@diegocardenas4522 the problem is that inmost cases, you don't need to use ssr in every page.

  • @Vantivify
    @Vantivify Год назад

    Yeah look into vitest and test context so probably you could PIT the Logic of creating caller to it and reuse within the tests

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад

      yes of course, but you'll want different callers for different tests

  • @ianbdb7686
    @ianbdb7686 Год назад

    The speed of u writing react code makes me wonder why anyone would pay me to do the something similar

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад

      That's the magic of video editing 😅

  • @madashindeinai4783
    @madashindeinai4783 Год назад +4

    Every second is a piece of gold. That's extremely helpful and imho should be linked in docs. Thx a lot!

  • @JohannPerezE
    @JohannPerezE Год назад

    This was really helpful. Subscribed

  • @yiannis_p
    @yiannis_p Год назад +3

    Amazing, thank you so much!
    If you needed to include session in the context, would you still use an ssg helper? (Sorry if it’s a dumb question, I’m a beginner)

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад +3

      Yes you can still use it. Whatever you're using to grab the session usually in middleware etc can also be used in gSSP to then pass to the SSG helper. Always remember: gSSP runs on the server, so you have all the same stuff.

  • @BriceSuazo
    @BriceSuazo Год назад

    Wow, thanks for this!

  • @howuseehim
    @howuseehim Год назад

    I didn't understand the question to begin with

  • @ekaansh
    @ekaansh Год назад +2

    great video, crisp delivery densely packed information! love it

  • @cablecardigital7671
    @cablecardigital7671 Год назад

    This may have been one of the most helpful YT videos I've ever seens. Thanks!

  • @RhysSullivan
    @RhysSullivan Год назад

    Great video thank you!

  • @petter9078
    @petter9078 Год назад

    Can you please explain how the dehydrate works and the prefetching in more detail? I knew what you mentioned already from the trpc docs.

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад +3

      it uses tanstack/react query's `useHydrate`/`dehydrate` behind the scenes. this page from the tanstack docs explains it better than i ever could: tanstack.com/query/v4/docs/react/reference/hydration

  • @juanmadelaflor6406
    @juanmadelaflor6406 Год назад

    Huge content quality thanks. Im trying to use your organization approach. One file per procedure. The procedure itself, schemas... etc. But Im using those schemas on the client too. Now Im getting the next error " You're trying to use @trpc/server in a non-server environment. This is not supported by default." How do you share the schemas then? Thanks again.

    • @ccccjjjjeeee
      @ccccjjjjeeee  Год назад +1

      uh oh, there does seem to be an issue currently where importing a zod schema in the frontend from a file that also exports a trpc router can lead to problems. i will open an issue about this. in the meantime i guess stick the schema in a different file :(

    • @juanmadelaflor6406
      @juanmadelaflor6406 Год назад

      @@ccccjjjjeeee Really thanks for your time