Тёмный

This Data Fetching Combo is OP 

Josh tried coding
Подписаться 136 тыс.
Просмотров 51 тыс.
50% 1

With this approach, we can get both benefits from server and client-side rendering. It's pretty neat, works well for me and I hope it does for you too!!
Stay up to date with web dev: www.joshtriedcoding.com/
-- my links
Discord: / discord
GitHub: github.com/joschan21

Наука

Опубликовано:

 

4 янв 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 120   
@joshtriedcoding
@joshtriedcoding 4 месяца назад
Hope you had a great start into the new year OR ELSE
@kumardeepanshu8503
@kumardeepanshu8503 4 месяца назад
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 4 месяца назад
Amazing job dude Waiting for the dashboard vid BTW But I hope you deploy it on a platform other than Railway
@alex_rpascual
@alex_rpascual 4 месяца назад
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.
@drprdcts
@drprdcts 4 месяца назад
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
@yassinesafraoui
@yassinesafraoui 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
@user-ym2tp6iq2p
@user-ym2tp6iq2p 4 месяца назад
Okay I'm totally unfamiliar with this concept but seems interesting. So, how can I learn more about it?
@MrGuysmo92
@MrGuysmo92 4 месяца назад
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...
@developedbyed
@developedbyed 4 месяца назад
Had to do a double take when I saw the thumbnail 😂 awesome stuff Josh ❤
@joshtriedcoding
@joshtriedcoding 4 месяца назад
appreciate ya man!!
@poizonncs8264
@poizonncs8264 4 месяца назад
@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 😅
@josephnaru363
@josephnaru363 4 месяца назад
I appreciate that you're concerned about promoting good practices in every video, keep it up!
@SubzEye
@SubzEye 4 месяца назад
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
@keshavakumar9828
@keshavakumar9828 4 месяца назад
In 7 mins i got to learn something new Going to play around with it. thanks josh
@Alireza-kw6fj
@Alireza-kw6fj 4 месяца назад
I randomly done this method in my app with react-query - but here someone is teaching it ;)
@manitahriri9204
@manitahriri9204 4 месяца назад
Hi josh, May I know what is the you are using for demonstration? It looks fantastic.
@abderehmen783
@abderehmen783 4 месяца назад
Josh, can you please make a video on how you make your RU-vid 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
@footyflair038
@footyflair038 4 месяца назад
Josh, you are my favorite react/nextjs teacher on youtube! Keep it up for our sake
@user-cq8yz1sz3s
@user-cq8yz1sz3s 4 месяца назад
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.
@user-cq8yz1sz3s
@user-cq8yz1sz3s 4 месяца назад
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 🥰
@xaviertromp2359
@xaviertromp2359 4 месяца назад
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 4 месяца назад
Next.js is simply doing what the React team tells them to... All react frameworks will eventually implement most of these same RSC features.
@sourav1795
@sourav1795 4 месяца назад
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
@Ahmed_005
@Ahmed_005 4 месяца назад
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 4 месяца назад
You can mutate the data with a HTTP request and revalidate the data. Both TanStack Query and SWR support such scenarios
@samislam2746
@samislam2746 4 месяца назад
I was thinking about the same thing before I saw your video notification
@amansagar4948
@amansagar4948 4 месяца назад
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
@JoseWaldier
@JoseWaldier 4 месяца назад
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 4 месяца назад
​@@JoseWaldier 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 4 месяца назад
@@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
@JoseWaldier
@JoseWaldier 4 месяца назад
@@amansagar4948 pagination. 🫳
@TheBelafleck
@TheBelafleck 4 месяца назад
Thanks for this awesome video ❤
@jordymaryns4945
@jordymaryns4945 4 месяца назад
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 :)
@jackmarius5423
@jackmarius5423 4 месяца назад
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 4 месяца назад
it's generated both on server and client, that's how next works
@jackmarius5423
@jackmarius5423 4 месяца назад
@@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
@juliusmarminge
@juliusmarminge 4 месяца назад
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?
@stylianostsoumanis3380
@stylianostsoumanis3380 4 месяца назад
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 4 месяца назад
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.
@kukiponosanhrvat
@kukiponosanhrvat 4 месяца назад
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.
@akosbalint3485
@akosbalint3485 4 месяца назад
initialData at 6:25 is equals to the dashboardData prop?
@samfights
@samfights 4 месяца назад
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 4 месяца назад
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 4 месяца назад
@@incarnateTheGreat I'm doing the same on a side project using a Zustand store, we need to have a better option!
@incarnateTheGreat
@incarnateTheGreat 4 месяца назад
@@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 4 месяца назад
"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 4 месяца назад
thank you.. i'll check it out @@CoryTheSimmons
@omarvillalobos5249
@omarvillalobos5249 4 месяца назад
what webapp do you use for sketching?
@user-ir3yw8bs4i
@user-ir3yw8bs4i 4 месяца назад
Crazy Frontend stuff ;) Let the server do its intrinsic job and Frontend what the word literally implies
@imposterdev789
@imposterdev789 4 месяца назад
Can you share the name of the tool you used in this video.
@paw565
@paw565 4 месяца назад
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 4 месяца назад
It doesnt really matter, whatever works best for you. I personally use fetch on server and axios + tanstack query on the client.
@paw565
@paw565 4 месяца назад
@@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 4 месяца назад
@@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 4 месяца назад
@@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 4 месяца назад
@@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."
@kacperwodarczyk9349
@kacperwodarczyk9349 4 месяца назад
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 4 месяца назад
Just set the options as searchParams and send them to your backend. No need for setState
@TutoDS2014
@TutoDS2014 4 месяца назад
What you are using for write the notes?
@albert21994
@albert21994 4 месяца назад
Thank you for reminding me that this exists :D
@IanJamieson
@IanJamieson 4 месяца назад
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 4 месяца назад
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
@nithinsvarrier670
@nithinsvarrier670 4 месяца назад
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
@albert21994
@albert21994 4 месяца назад
have you used the initial data property?
@nithinsvarrier670
@nithinsvarrier670 4 месяца назад
@@albert21994 Yes
@TheGrandChieftain
@TheGrandChieftain 4 месяца назад
Work with the enabled prop
@asimalqasmi7316
@asimalqasmi7316 4 месяца назад
Thanks
@StivenRusTV
@StivenRusTV 4 месяца назад
how josh create this good code animation ?
@RABWA333
@RABWA333 4 месяца назад
Do you have full stack Nextjs course ?
@sahibnasirri5581
@sahibnasirri5581 4 месяца назад
OOT: does anyone knows which design ui Josh use here? thanks in advance
@user-us3bs8px3m
@user-us3bs8px3m 4 месяца назад
You solved the bug.
@user-ju8cu3ru4d
@user-ju8cu3ru4d 4 месяца назад
Could someone tell me the tool he is using to draw and show, thanks !
@mathiasriissorensen6994
@mathiasriissorensen6994 4 месяца назад
Excalidraw
@beynod_ordinary
@beynod_ordinary 4 месяца назад
What tools are used for text prototyping? Thanks
@_Spacecraft
@_Spacecraft 4 месяца назад
Also wondering this
@alex-wj6ce
@alex-wj6ce 4 месяца назад
@@_Spacecraft check out excalidraw
@beynod_ordinary
@beynod_ordinary 4 месяца назад
No reply yet.@@_Spacecraft
@adamkirosingh
@adamkirosingh 4 месяца назад
excalidraw
@sebastiancastillo3560
@sebastiancastillo3560 4 месяца назад
Is it possible to do the entire nextjs project client side rendering? thanks Josh!!!
@amansagar4948
@amansagar4948 4 месяца назад
@@ShivWad hey "use client" also renders on the server. do not misguide others in the wild
@kisstamas6675
@kisstamas6675 4 месяца назад
@@amansagar4948 then whats the difference if i use "use client" or i not?
@nithinsvarrier670
@nithinsvarrier670 4 месяца назад
@@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 4 месяца назад
@@nithinsvarrier670 ahh. Thanks for the info. I will edit my comment
@rand0mtv660
@rand0mtv660 4 месяца назад
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.
@outis99
@outis99 4 месяца назад
Before watching this I'm guessing it's about react query's initial data feature
@rtorcato
@rtorcato 4 месяца назад
what is the diagram tool you use?
@umaradam3788
@umaradam3788 4 месяца назад
I'm curious too
@mathiasriissorensen6994
@mathiasriissorensen6994 4 месяца назад
Excalidraw
@rtorcato
@rtorcato 4 месяца назад
@@mathiasriissorensen6994 thanks
@joshtriedcoding
@joshtriedcoding 4 месяца назад
Excalidraw!
@rootbindev
@rootbindev 4 месяца назад
You are good
@ekchills6948
@ekchills6948 4 месяца назад
Sweet logic
@ashishsharma__
@ashishsharma__ 4 месяца назад
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 4 месяца назад
mfer is pushing his homework on 3rd parties
@ashishsharma__
@ashishsharma__ 4 месяца назад
@@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.
@MelodyMixMusic017
@MelodyMixMusic017 4 месяца назад
Bro you can build AI voice assistant chatbots and add 10 different voice to speak you can build this application
@imkir4n
@imkir4n 4 месяца назад
ozm
@prashlovessamosa
@prashlovessamosa 4 месяца назад
Hello Josh.
@joshtriedcoding
@joshtriedcoding 4 месяца назад
waddup champ
@Fresco7
@Fresco7 4 месяца назад
Great a
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@user-yz5yo1hd7k
@user-yz5yo1hd7k 4 месяца назад
Please do a proper video on this, with some demos 😀😀
@EPIC-ev4lx
@EPIC-ev4lx 4 месяца назад
Are you used to play vedio games 😅? So you can came up with this title
@joshtriedcoding
@joshtriedcoding 4 месяца назад
yeah man I play every now and then!
@farzadmf
@farzadmf 4 месяца назад
"lots of other cool shit" 😅
@joshtriedcoding
@joshtriedcoding 4 месяца назад
hell yeah
@xxXAsuraXxx
@xxXAsuraXxx 4 месяца назад
Man just use remix
@JakobRossner-sc3gp
@JakobRossner-sc3gp 4 месяца назад
Theo says that seperation of concerns is bad: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-eMTFzpxR0QQ.htmlfeature=shared
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
@developertools95
@developertools95 4 месяца назад
build a nextjs tutorial plz
Далее
I Never Want To Fetch Data Any Other Way
7:19
Просмотров 62 тыс.
Are React client components bad?
4:21
Просмотров 29 тыс.
Do I even need this anymore?
5:41
Просмотров 45 тыс.
10 分钟 理论 + 实操 搞懂 WebSocket
9:03
Просмотров 11 тыс.
I Didn't Know Next.js Server Actions Could Do This!
6:53
Refactoring a React component - Design Patterns
15:19
Why Signals Are Better Than React Hooks
16:30
Просмотров 449 тыс.
10 common mistakes with the Next.js App Router
20:37
Просмотров 175 тыс.
This UI Library Keeps Crushing It
4:36
Просмотров 64 тыс.