Тёмный

React Query Tutorial with Typescript | Part 5 -- Next.js Server Side Rendering 

CodeDunks
Подписаться 7 тыс.
Просмотров 12 тыс.
50% 1

In this video, I will be talking about how to use server side rendering in react-query with Next.js
React query documentation: react-query.tanstack.com/over...
Starter Project: github.com/leoroese/reactquer...
Finished ReactQuery Tutorial Project: github.com/leoroese/reactquer...
Timestamps
0:00 Intro
1:00 initialData method
7:15 hydration method

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

 

4 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@ndstephens
@ndstephens 2 года назад
excellent series. best vids i've seen on React-Query hands down. thank you
@jesper9334
@jesper9334 2 года назад
Best series out there about React Query, Thank you
@khpeiris
@khpeiris 2 года назад
Please use the zoomed-out version so we could see more code. also, make the vscode wrapped while you are at it. Thanks for the video. cheers!
@CodeDunks
@CodeDunks 2 года назад
Wow I didn’t even know that you could wrap it like that. Game changer! Huge thanks haha
@kaisian4940
@kaisian4940 3 года назад
I like your content. Bigger is better, I will pick the first zoom size
@idrisisholaagboola8676
@idrisisholaagboola8676 Год назад
Thank you for this amazing tutorial it really helps me.
@johnifemezuo2641
@johnifemezuo2641 2 года назад
thanks alot..your video was actually helpful to me
@muratasarslan2359
@muratasarslan2359 Год назад
Hi Leo, wonderful videos, thanks! One question; let's say our client cache update on client side. It's deviated from server cache. Then we renavigate to our page. existing server cache will be dehydrated and sent to client. Are we gonna reconcile rehydrated server cache data on the client with already daviated client side cache? Regards...
@flavioneto1081
@flavioneto1081 Год назад
very helpful bro, thanks
@language_ai
@language_ai 2 года назад
Awesome!
@tobychidi
@tobychidi Год назад
Cool stuff
@amirmasoodjafari3207
@amirmasoodjafari3207 2 года назад
thank you for the video ... with this approach i have some problems with implementing infinite scrolling ! i need to use prevState and new Data like this [ ...prev,...data ] and i don't know how to do it with react query !
@stevereid636
@stevereid636 Год назад
Looks like when you demonstrated hydration, you were still on the initialData page? 😜
@artursradionovs9543
@artursradionovs9543 2 года назад
Hi Can someone help me with React Query and Next Js dynamic data rendering?
@yogyyconst
@yogyyconst Год назад
why i still see it fetch in network(client),
@mohammedkudmani2195
@mohammedkudmani2195 2 года назад
Hello, is it fine if i used my own api in next.js and react-query cuz in the docs next.js says to never use your own api
@CodeDunks
@CodeDunks 2 года назад
Of course you can use your own api! Curious, where in the docs does it say that?
@stevereid636
@stevereid636 Год назад
How come when using hydration we no longer need an absolute url in GetServerSideProps!?! Great seriies btw. UPDATE: Just noticed that "TypeError: Only absolute URLs are supported" is actually still coming up in the terminal, so I have my answer
@rambosweat
@rambosweat 2 года назад
the implementation looks more like a general get LIST of persons, instead of an individual person via id. I am unable to find an example of useQuery that actuall uses url params from nextjs useRouter.
@CodeDunks
@CodeDunks 2 года назад
Found this prateeksurana.me/blog/mastering-data-fetching-with-react-query-and-next-js/ CTRL + F and searching router then got to this example const router = useRouter(); const pokemonID = typeof router.query?.id === "string" ? router.query.id : ""; const { isSuccess, data: pokemon, isLoading, isError } = useQuery( ["getPokemon", pokemonID], () => fetchPokemon(pokemonID), { enabled: pokemonID.length > 0 } );
@timetosleep8055
@timetosleep8055 Год назад
SSR example: const id = context.params?.id; await queryClient.prefetchQuery(["artist", id], () => getArtistById(id!), { staleTime: Infinity, refetchOnWindowFocus: false, }); CSR example: const { query } = useRouter(); const { id } = query; const { data: artist } = useQuery(["artist", id], () => getArtistById(id!), { staleTime: Infinity, refetchOnWindowFocus: false, });
@tomaszolech4132
@tomaszolech4132 2 года назад
ok but what are the benefits of using react query with server side why not just use client side?
@CodeDunks
@CodeDunks 2 года назад
A benefit with pre fetching data on server side then rendering is that the data will be available upon render. Meaning you don't have to deal with "no-data" states. Here is a cool article explaining the differences dev.to/fenok/client-and-server-side-data-fetching-in-react-4o7d
@sreekumarmenon
@sreekumarmenon 3 года назад
questtioin- when we use getserversideprops ,next.js does an api call to server, so which means while doing client side navigation it does not use the cached data and make api call ,is that rt? i dont think server side can access client sidee cached data?
@CodeDunks
@CodeDunks 3 года назад
Yes I believe you are correct unless I may have missed something in the documentation. But I believe the server shouldn't be able to be aware of the client side cache.
@sreekumarmenon
@sreekumarmenon 3 года назад
@@CodeDunks I switched to getInitiialProps for this reason ,getInitialProps run on client side on client side navigation. I dont think this is mentioned in any documentation or Tutorials
@CodeDunks
@CodeDunks 3 года назад
@@sreekumarmenon Yeah from next.js docs it says getInitialProps will run on the server on initial page load. It would then run on the client when navigating to a different route using next/link. nextjs.org/docs/api-reference/data-fetching/getInitialProps. I figured that this meant that the initial page load would still not be able to use query cache since it is run on the server for the first-page load.
@sreekumarmenon
@sreekumarmenon 3 года назад
@@CodeDunks so on iniitial page load ,there is no cache if you do a full page refresh, cache is gone anyways. so you are right, for getInitiialProps, first time query is executed on server and the hydrated to client side and cache is initialized and then onwards getInitialProps can read from cache, but that is not the case with getServerSideProps.
@CodeDunks
@CodeDunks 3 года назад
@@sreekumarmenon Yup makes sense! Thanks for all the info!
@usmanmughal5916
@usmanmughal5916 2 года назад
Why are you applying types twice? do it once in the Generic and the constant will infer to it automatically.
@CodeDunks
@CodeDunks 2 года назад
I was doing it more for sake of transparency for the tutorial. Thinking it might help others understand a little bit better when it is explicitly shown what the type is.
@usmanmughal5916
@usmanmughal5916 2 года назад
@@CodeDunks Believe someone at the stage of learning react-query is not a kid. He knows the basic shit :P well thanks nice tutorial.
@CodeDunks
@CodeDunks 2 года назад
@@usmanmughal5916 Appreciate it Usman and thanks for the feedback!
Далее
MobX Tutorial with React and Typescript
35:53
Просмотров 17 тыс.
Stray Kids <ATE> UNVEIL : TRACK "Stray Kids"
01:28
Просмотров 636 тыс.
Can We Save Goku In 5 SECONDS⁉️😰 #dbz #goku
00:15
NextJS + State Management = Good Idea???
41:08
Просмотров 97 тыс.
NextJS 13 WARNING: Easy Mistake = Infinite Loops
23:46
MaterialUI Flexbox & Grid Tutorial
21:20
Просмотров 14 тыс.
Next.js 13… this changes everything
6:16
Просмотров 773 тыс.