Advanced tRPC - Callers, functions, and gSSP

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ • 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)

  • @madashindeinai4783
    @madashindeinai4783 Рік тому +4

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

  • @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

  • @cablecardigital7671
    @cablecardigital7671 Рік тому

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

  • @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!

  • @ekaansh
    @ekaansh Рік тому +2

    great video, crisp delivery densely packed information! love it

  • @JohannPerezE
    @JohannPerezE Рік тому

    This was really helpful. Subscribed

  • @xXFlameSwordsmanXx
    @xXFlameSwordsmanXx Рік тому

    Waiting for that testing T3/TRPC video!!

  • @Manmanolo115
    @Manmanolo115 Рік тому +1

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

  • @gabrielbianchi2246
    @gabrielbianchi2246 Рік тому

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

  • @SonAyoD
    @SonAyoD Рік тому +1

    great video! more trpc stuff please

  • @pmioduszewski
    @pmioduszewski Рік тому

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

  • @BriceSuazo
    @BriceSuazo Рік тому

    Wow, thanks for this!

  • @marketinga2z
    @marketinga2z Рік тому

    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! 😂

  • @oscartbeaumont
    @oscartbeaumont Рік тому +1

    Great videos!

  • @mendylanda125
    @mendylanda125 Рік тому

    Great content! ❤
    Thank you 🙏

  • @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.

  • @RhysSullivan
    @RhysSullivan Рік тому

    Great video 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 :)

  • @juliusmarminge
    @juliusmarminge Рік тому +1

    Niceeee

  • @infisspablo8602
    @infisspablo8602 Рік тому

    nice!

  • @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

  • @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

  • @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

  • @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 :)

    • @facuflooo
      @facuflooo Рік тому +1

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

  • @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 😅

  • @howuseehim
    @howuseehim Рік тому

    I didn't understand the question to begin with