This Data Fetching Combo is OP

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 122

  • @joshtriedcoding
    @joshtriedcoding  ปีที่แล้ว +31

    Hope you had a great start into the new year
    OR ELSE

    • @kumardeepanshu8503
      @kumardeepanshu8503 ปีที่แล้ว

      I have a question, how did you pass the initial data to your useQuery, as I am using trpc, but I cannot do that and the refetchinterval, ? can you explain it bit , it will be very help full . Thank you

    • @ahmed_osamaa
      @ahmed_osamaa ปีที่แล้ว

      Amazing job dude
      Waiting for the dashboard vid BTW
      But I hope you deploy it on a platform other than Railway

  • @developedbyed
    @developedbyed ปีที่แล้ว +12

    Had to do a double take when I saw the thumbnail 😂 awesome stuff Josh ❤

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +1

      appreciate ya man!!

    • @poizonncs8264
      @poizonncs8264 ปีที่แล้ว +1

      @developedbyed You are great man, i have implemented this server side prefetching after watching your after your video. But i prefetch on on my layout component 😅

  • @mjylove2
    @mjylove2 5 หลายเดือนก่อน +1

    thank you so much. your visualization of the fetching data is really helpful

  • @alex_rpascual
    @alex_rpascual ปีที่แล้ว +54

    For polling you can also do Server-Sent Events (SSE). The server sends the data with the 'content-type' header set to 'text/event-stream' and the client listen to that with the EventSource API.

    • @flexdash
      @flexdash ปีที่แล้ว

      If you're not using http/2, SSE will have a 6 connection limit. If your client opens 6 tabs to your website, they will no longer be able to send any http requests to your website. Basically, SSE is pretty much useless in http/1.1

    • @yassine-sa
      @yassine-sa ปีที่แล้ว +4

      Yes that's better because you don't need a persistent connection that websockets require and that is not an option on edge and at the same time there is no delay between when the data was available to the server and when the fetched it which is the problem with polling. But I wonder what are the drawbacks of server sent events? The only one I can think of is that it's a unidirectional communication, but can't we use post requests to send data from the client to the server, I think it would work and the only problem I see with this approach is that receiving data and sending it is done separately so it's not optimal if receiving data and sending it are coupled

    • @FaridaYesmin-b6h
      @FaridaYesmin-b6h 11 หลายเดือนก่อน +2

      Okay I'm totally unfamiliar with this concept but seems interesting. So, how can I learn more about it?

  • @josephnaru363
    @josephnaru363 ปีที่แล้ว +3

    I appreciate that you're concerned about promoting good practices in every video, keep it up!

  • @SubzEye
    @SubzEye ปีที่แล้ว +2

    For me one of the most important reason for splitting Backend calls between server and client side is the fact that server side calls are Blocking calls, therefore if we are dealing with large volume of data on server side then it will cause delay in page load by delaying the first content paint

  • @Alireza-kw6fj
    @Alireza-kw6fj ปีที่แล้ว

    I randomly done this method in my app with react-query - but here someone is teaching it ;)

  • @MrGuysmo92
    @MrGuysmo92 ปีที่แล้ว +13

    It's an interesting approach. But what about caching and revalidating data? I assume that on the server side, we can perform revalidation based solely on time. Then, on the client side, we can easily revalidate data using the 'useQuery' capability when executing a mutation.
    Is this the correct approach? I'm getting tired of dealing with Next.js revalidation...

  • @footyflair038
    @footyflair038 ปีที่แล้ว

    Josh, you are my favorite react/nextjs teacher on youtube! Keep it up for our sake

  • @amansagar4948
    @amansagar4948 ปีที่แล้ว +9

    I was thinking about this yesterday while following one of your tutorials that if the data fetching can be done on the sever (irrespective of server componennts) then why we need react query at all. I guess, 60% of the time, fetching data on the server should do

    • @jsvrs
      @jsvrs ปีที่แล้ว

      but the problem arise when fetching from dynamic components like buttons, forms, etc (e.g fetching from client-side). You can't really fetch from server on those cases (unless you do server actions). So here it's where Tanstack query shines.

    • @amansagar4948
      @amansagar4948 ปีที่แล้ว +1

      ​@@jsvrs fetching what exactly? most buttons leads to a separate route. forms are strictly advised to be submitted via server actions in next14
      data fetching in general makes very less sense after the RSCs

    • @PraiseYeezus
      @PraiseYeezus ปีที่แล้ว

      @@amansagar4948 not all data fetching is tied to a button. maybe your component is an autocomplete form where it searches as the user types. makes more sense to fetch that data clientside

    • @jsvrs
      @jsvrs 11 หลายเดือนก่อน

      @@amansagar4948 pagination. 🫳

  • @vaibhavn.k8440
    @vaibhavn.k8440 5 หลายเดือนก่อน

    In your project for the first site visit time the page is served directly by the server with the data from database (first time is slow because server has to get data from database usually situated far ), then because you need a realtime data fetch every 10 seconds you write a logic that runs client side to keep fetching the data and updating the graph component (well websocket is fine but we still can use the simple https for cases where the rate of data updates is relatively low , maybe it updates 10 times a minute or so).In client side you also write the logic for graph changes everytime so in one . But do you think its really effective in terms of compute power requirement. Does it really save considerable amount of money for the website owners. because the fetching of data every 10 seconds is not really that big of a compute. Excluding case where the software is an admin side e commerce dashboard with high sales.

  • @samfights
    @samfights ปีที่แล้ว +3

    What if you need to update the UI immediately after a user action, what is the best approach? (while updating also the DB)

    • @incarnateTheGreat
      @incarnateTheGreat ปีที่แล้ว +1

      I'm doing this on a learning project right now. I initially load from the server, but then hydrate/update by clicking a button that uses useTransition. It re-fires the server-side function and gets the updated data and html.
      Have to say, it feels like a workaround, but it works for now.

    • @samfights
      @samfights ปีที่แล้ว +1

      @@incarnateTheGreat I'm doing the same on a side project using a Zustand store, we need to have a better option!

    • @incarnateTheGreat
      @incarnateTheGreat ปีที่แล้ว +1

      @@samfights the way Next builds projects is that they do canary releases, which is like doing experimental releases into production.
      My hope is that they're drumming up a better way to handle this.

    • @CoryTheSimmons
      @CoryTheSimmons ปีที่แล้ว +2

      "Optimistic UI" is the term you're looking for.
      SWR's optimistic UI + Immer example is the cleanest thing I've ever seen.

    • @samfights
      @samfights ปีที่แล้ว

      thank you.. i'll check it out @@CoryTheSimmons

  • @samislam2746
    @samislam2746 ปีที่แล้ว

    I was thinking about the same thing before I saw your video notification

  • @Olti-p2h
    @Olti-p2h ปีที่แล้ว +11

    Hey Josh,
    I've been a huge fan of your videos, and your programming skills always leave me in awe. Your projects are truly inspiring, and I've learned so much from watching your content. I aspire to become as proficient as you in programming.
    I have a request for a video idea that I think would benefit many, including myself. Could you consider creating a tutorial using Next.js 14, Appwrite, Shadcn with Zod for authentication? I find it challenging as a beginner, especially when incorporating Zod, Toast Messages, and storing user account details in the database.

    • @Olti-p2h
      @Olti-p2h ปีที่แล้ว +8

      It would be great if you could also touch upon the fact that with AppWrite, user accounts are stored in Authentications. I suggest covering how to save these accounts as users in the database, enabling relationships and potentially exploring features.
      Additionally, demonstrating how users can upload, change, or remove their profile pictures, and having the default picture from AppWrite would be fantastic. Also, allowing users to modify their names and email addresses in their profiles.
      I appreciate your time and expertise. It would mean a lot to me, and I'm sure many others would find this tutorial incredibly beneficial.
      Thank you for considering my extended request!
      Grüße 🥰

  • @jaysolanki6572
    @jaysolanki6572 2 หลายเดือนก่อน

    What about Next.js data caching layer which persists the result of data fetches across incoming server requests and deployments??
    React Query could fetch the data on server but what about caching it across the server request?
    It's surely a solution in one scenario and providing caching solution for single user only.

  • @xtromp
    @xtromp ปีที่แล้ว +9

    Is it possible to recreate a similar experience but without next.js, with like tanstack-router and hono or elysia, or something else? Hate the direction next.js is taking with way too much magic at so many levels..

    • @KevinVandyTech
      @KevinVandyTech ปีที่แล้ว +1

      Next.js is simply doing what the React team tells them to... All react frameworks will eventually implement most of these same RSC features.

    • @teenytinyteetee
      @teenytinyteetee 5 หลายเดือนก่อน

      Interesting take… I can agree with this point a bit.. can suck out some of the fun or flexibility 😅

  • @imposterdev789
    @imposterdev789 ปีที่แล้ว +1

    Can you share the name of the tool you used in this video.

  • @abderehmen783
    @abderehmen783 ปีที่แล้ว +2

    Josh, can you please make a video on how you make your TH-cam videos and the Softwares that you use in your videos, I really like the way you animate the code and the way you explain the ideas on a board

  • @keshavakumar9828
    @keshavakumar9828 ปีที่แล้ว

    In 7 mins i got to learn something new
    Going to play around with it. thanks josh

  • @TheBelafleck
    @TheBelafleck ปีที่แล้ว

    Thanks for this awesome video ❤

  • @TutoDS2014
    @TutoDS2014 11 หลายเดือนก่อน

    What you are using for write the notes?

  • @akosbalint3485
    @akosbalint3485 ปีที่แล้ว

    initialData at 6:25 is equals to the dashboardData prop?

  • @nithinsvarrier670
    @nithinsvarrier670 ปีที่แล้ว +2

    I did this for a project sometime ago. But the problem with react query is that it will refetch the data once more on page load due to staleTime being 0

  • @juliusmarminge
    @juliusmarminge 11 หลายเดือนก่อน

    Edge runtime doesnt automatically mean you put the server close to the user, you can (which is the default when deploying on vercel) use the edge runtime in a single region. I think global is an enterprise feature, no?

  • @sahibnasirri5581
    @sahibnasirri5581 ปีที่แล้ว

    OOT: does anyone knows which design ui Josh use here? thanks in advance

  • @鍾至漢
    @鍾至漢 ปีที่แล้ว +1

    Could someone tell me the tool he is using to draw and show, thanks !

  • @albert21994
    @albert21994 ปีที่แล้ว

    Thank you for reminding me that this exists :D

  • @kukiponosanhrvat
    @kukiponosanhrvat 11 หลายเดือนก่อน

    Could you make a video of combining server actions with React Query? Where you would do mutations on server and use React Query to manage state, cache, handle errors, etc... Also by using server actions you would always have a benefit of really fast data transfer, since data is being handled on server side. I'm just starting to use both of these, so maybe i'm wrong and maybe this is not a good combination. Would like to hear others opinion.

  • @jordymaryns4945
    @jordymaryns4945 ปีที่แล้ว

    Question: When polling for "real time" data, if you fetch every 5 seconds, is cost a concern? Because I thought that if you continuously fetch data that you needed websockets for some reason to keep cost in check?
    Anyone with a good explanation? much appreciated :)

  • @StivenRusTV
    @StivenRusTV 11 หลายเดือนก่อน

    how josh create this good code animation ?

  • @stylianostsoumanis3380
    @stylianostsoumanis3380 ปีที่แล้ว +1

    What if our backend/api is completely seperate from next.js? For example a Go backend etc... What do you think would be the best approach for something like that?

    • @Xeras82
      @Xeras82 11 หลายเดือนก่อน

      You can fetch from the remote api on the server-side and with tanstack/query on the client-side ... that's no deal breaker. Doens't matter where you fetch from.

  • @edhahaz
    @edhahaz 7 หลายเดือนก่อน

    You need to finsih the saga how does this tie in with react querry, suspense streaming and optimistic updates? Can't wrap my head around it..

  • @RABWA333
    @RABWA333 ปีที่แล้ว

    Do you have full stack Nextjs course ?

  • @Ahmed_005
    @Ahmed_005 ปีที่แล้ว +1

    Great video, but what should we do if the client component needs to update the data through for example a POST request? Appreciate if you could link the GitHub repo used for this video as well.

    • @pieterdepauw6599
      @pieterdepauw6599 ปีที่แล้ว

      You can mutate the data with a HTTP request and revalidate the data. Both TanStack Query and SWR support such scenarios

  • @IanJamieson
    @IanJamieson ปีที่แล้ว

    I had look at t3 stack for a project. All seems ok for something small, but creating all these zod types was a nightmare. Ended up with zod prisma types to generate them all, but in the end everything ran so slow I scrapped it. Ts slow, eslint crashing etc. Now just plain server actions, and api routes with tanstack query only for specific places where I need to fetch data client side only i.e common form selects with country data

    • @outis99
      @outis99 ปีที่แล้ว

      Do you think this is a hardware issue from your part? I have the same setup with zod prisma types and everything runs pretty smoothly. I have a Ryzen 5800x with 32GB RAM

  • @rtorcato
    @rtorcato ปีที่แล้ว +1

    what is the diagram tool you use?

  • @omarvillalobos5249
    @omarvillalobos5249 ปีที่แล้ว

    what webapp do you use for sketching?

  • @satyak1337
    @satyak1337 4 หลายเดือนก่อน

    i just dont want to use server component anymore. The complexity it adds is insane. I spent 3 hours trying to go through supabase and understand how to fetch data in server components.

  • @Gohealt
    @Gohealt ปีที่แล้ว

    Crazy Frontend stuff ;) Let the server do its intrinsic job and Frontend what the word literally implies

  • @manitahriri
    @manitahriri 11 หลายเดือนก่อน

    Hi josh, May I know what is the you are using for demonstration? It looks fantastic.

  • @kacperwodarczyk9349
    @kacperwodarczyk9349 ปีที่แล้ว

    I have 1 big problem with nextjs how to make a nice filter, sorting, search form with data fetched from API
    for example i have an endpoint /api/offer and i can add multiply query search /api/offer?ordering=-created_at&search=xyz?is_remote=true
    How to make it in nextjs ?
    Currently i use useState and after form submit i fetch the data but in frontend app URL nothing change which for me doesn't look good, is there a way to make it better?

    • @IanJamieson
      @IanJamieson ปีที่แล้ว

      Just set the options as searchParams and send them to your backend. No need for setState

  • @sourav1795
    @sourav1795 ปีที่แล้ว

    hey josh i just wanna ask if i can use nodejs for backend instead of nextjs any cons and prons in terms of improvement and speed

  • @jackmarius5423
    @jackmarius5423 ปีที่แล้ว +1

    Is the dashboard rendered as HTML directly from the server or it is hydrating the data and the js will generate the UI?

    • @roxxel8167
      @roxxel8167 ปีที่แล้ว

      it's generated both on server and client, that's how next works

    • @jackmarius5423
      @jackmarius5423 ปีที่แล้ว

      @@roxxel8167 Well, not really, on the pages router, you get the data in a script tag and the component that uses that data is rendered on the client, so the HTML comes without that component that has dynamic data from the server.
      I was curious if now with server components, would the component be built into HTML at first call rather than hydrating the data

  • @paw565
    @paw565 ปีที่แล้ว

    Is it OK to use fetch on the server (because it's cached in next js) and axios + react query on the client? Or is it better to just stick to only axios or fetch?

    • @REAZNx
      @REAZNx ปีที่แล้ว +1

      It doesnt really matter, whatever works best for you. I personally use fetch on server and axios + tanstack query on the client.

    • @paw565
      @paw565 ปีที่แล้ว

      @@REAZNx thank you for the response! I just thought that mixing fetch and axios in one project is considered as a bad practice.

    • @REAZNx
      @REAZNx ปีที่แล้ว

      @@paw565 Yeh I get that, Axios is just better in almost every way, except for the obvious nextjs cache you get from fetch. I wouldn't really worry about it, most people do it this way in nextjs :)

    • @paw565
      @paw565 ปีที่แล้ว

      @@REAZNx I just realized that I have to basically write each of my fetching functions twice. One with fetch for server, and one with axios for the client and react query. Seems like a whole a lot of repetition :/ Is there anyway to fix this?

    • @rand0mtv660
      @rand0mtv660 ปีที่แล้ว

      @@paw565 experimental "cache" function might be what you are looking for. Nextjs docs suggest using that. It might potentially be what they are using for that fetch deduping internally. I haven't tested it personally so I cannot say for sure.
      This is an excerpt from the docs:
      "For cases where fetch is not suitable (e.g. some database clients, CMS clients, or GraphQL clients), you can use the React cache function to memoize functions."

  • @outis99
    @outis99 ปีที่แล้ว

    Before watching this I'm guessing it's about react query's initial data feature

  • @sebastiancastillo3560
    @sebastiancastillo3560 ปีที่แล้ว

    Is it possible to do the entire nextjs project client side rendering? thanks Josh!!!

    • @amansagar4948
      @amansagar4948 ปีที่แล้ว

      @@ShivWad hey "use client" also renders on the server. do not misguide others in the wild

    • @kisstamas6675
      @kisstamas6675 ปีที่แล้ว

      @@amansagar4948 then whats the difference if i use "use client" or i not?

    • @nithinsvarrier670
      @nithinsvarrier670 ปีที่แล้ว

      @@ShivWad "use client" renders on the server and then hydrates on the client. If you need the render to be only on the client, you need to dynamically load the component and use option noSSR

    • @ShivWad
      @ShivWad ปีที่แล้ว

      @@nithinsvarrier670 ahh. Thanks for the info. I will edit my comment

    • @rand0mtv660
      @rand0mtv660 ปีที่แล้ว

      Check out their docs about "Migrating from Vite". There they explain how to set up a fully client rendered Nextjs app if you need that. Not sure why would you want that, but yes it does exist as an option.

  • @ekchills6948
    @ekchills6948 ปีที่แล้ว

    Sweet logic

  • @ashishsharma__
    @ashishsharma__ ปีที่แล้ว

    Can you make a video on a topic -
    A next js app that uses firebase authentication and rtk query to fetch data from a express server, the express server fetch data from mongodb.
    *The nextjs uses server side data fetching for authenticated user*

    • @Yusuf-ok5rk
      @Yusuf-ok5rk ปีที่แล้ว +1

      mfer is pushing his homework on 3rd parties

    • @ashishsharma__
      @ashishsharma__ ปีที่แล้ว

      @@Yusuf-ok5rk it's not homework buddy I'm already working in a IT company. I'm just trying to achieve this from months but couldn't so I just used client side fetching because on the server side I can't get cookies.

  • @asimalqasmi7316
    @asimalqasmi7316 ปีที่แล้ว

    Thanks

  • @rootbindev
    @rootbindev ปีที่แล้ว

    You are good

  • @MindSphere017
    @MindSphere017 ปีที่แล้ว

    Bro you can build AI voice assistant chatbots and add 10 different voice to speak you can build this application

  • @prashlovessamosa
    @prashlovessamosa ปีที่แล้ว

    Hello Josh.

  • @MdAzimBabu-i8u
    @MdAzimBabu-i8u ปีที่แล้ว

    Please do a proper video on this, with some demos 😀😀

  • @EPIC-ev4lx
    @EPIC-ev4lx ปีที่แล้ว

    Are you used to play vedio games 😅?
    So you can came up with this title

  • @Fresco7
    @Fresco7 ปีที่แล้ว

    Great a

  • @imkir4n
    @imkir4n ปีที่แล้ว

    ozm

  • @farzadmf
    @farzadmf ปีที่แล้ว

    "lots of other cool shit" 😅

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @hufor1996
    @hufor1996 3 หลายเดือนก่อน

    man this is really amazing explanation and thank you for that, but you really talk to much and you have no code explanation, you should show us how we can code this and dive deeper into the code not just on top level.

  • @JakobRossner-sc3gp
    @JakobRossner-sc3gp ปีที่แล้ว +1

    Theo says that seperation of concerns is bad:
    th-cam.com/video/eMTFzpxR0QQ/w-d-xo.htmlfeature=shared

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz

  • @developertools95
    @developertools95 ปีที่แล้ว

    build a nextjs tutorial plz