Тёмный

Fetching Data with Nextjs | 3 Different Patterns 

Ras Mic
Подписаться 20 тыс.
Просмотров 16 тыс.
50% 1

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

 

26 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 154   
@joshchant5003
@joshchant5003 4 месяца назад
Unpaid interns was personal
@rasmic
@rasmic 4 месяца назад
im sorry g lol
@3illanon145
@3illanon145 4 месяца назад
😂😂😂
@mDHARYL
@mDHARYL 4 месяца назад
Hahahahha😂😅
@caceresjuan
@caceresjuan 4 месяца назад
I struggled a lot with finding a simple and optimal way to fetch data in the client with nextjs 14, now that I saw your video I am going to start using tanstack + server actions, it is a brutal combo because it makes it easier for you to refetch and the states like loading and error, etc but above all the data caching. Thanks man ❤
@rasmic
@rasmic 4 месяца назад
appreciate u g, glad it was helpful
@maksymdudyk1718
@maksymdudyk1718 4 месяца назад
Next.js is a King of forcefull caching! Why do you need React-query with Next.js at all?
@caceresjuan
@caceresjuan 4 месяца назад
@@maksymdudyk1718 Yes but Next.js only caches GET requests and if you fetch data with a server action always will be a POST request and it is not cached by default, and if you are fetching in the client is a pain in the as* caching the server action. I struggled with it.
@caceresjuan
@caceresjuan 4 месяца назад
@@maksymdudyk1718 Yes but Next.js only caches by default GET requests and if you fetch data with a server action is always by default a POST request and is not cached by default. I think the nextjs team is working on being able to change the method type of the server action but today it is by default POST
@caceresjuan
@caceresjuan 4 месяца назад
@@maksymdudyk1718 Yes but Next.js caches GET requests and if you fetch data with a server action that is a POST request and is not cached by default. I think the nextjs team is working on enabling changing the request type of the server actions but at the moment they are POST by default.
@lucaszapico926
@lucaszapico926 Месяц назад
Thanks for the video it was clarifying. If you want a content suggestion, extending this video which how these patterns do or do not securely expose env vars is an opportunity. Just chirping. Thanks for the content.
@joshchant5003
@joshchant5003 4 месяца назад
Love these small specific videos!
@rasmic
@rasmic 4 месяца назад
glad u enjoyed g
@CodeZakk
@CodeZakk 4 месяца назад
you dropped the video when I needed it thanks mic!! the tanstack query is by far the best option. i've used the server action alone to fetch but it has some problem 1, it doesn't pass the error data properly 2, you can't pass the function directly to the client components
@rasmic
@rasmic 4 месяца назад
nice, hope it helps
@isdartho
@isdartho 4 месяца назад
Love how you clearly explain everything
@rasmic
@rasmic 4 месяца назад
Thanks for watching my g
@bodywithoutasoul
@bodywithoutasoul 4 месяца назад
Thank you for this! It was short and informative. Love it. Keep ‘‘em coming!
@rasmic
@rasmic 4 месяца назад
Will do my g, thanks for the kind words
@13yadav
@13yadav 4 месяца назад
great video man cleared alot of doubts re. fetching data in nextjs
@rasmic
@rasmic 4 месяца назад
glad it helped my g
@ktran
@ktran 4 месяца назад
You’re cooking bro, love these videos
@rasmic
@rasmic 4 месяца назад
Glad you like them!
@causecaos
@causecaos 4 месяца назад
These videos are killer, thanks for putting these out! Super useful
@rasmic
@rasmic 4 месяца назад
thanks g
@loganford5443
@loganford5443 4 месяца назад
these videos are amazing, keep them coming!
@rasmic
@rasmic 4 месяца назад
Thanks g, will do
@seifghost8619
@seifghost8619 4 месяца назад
i am rly glad i found ur channel thanks for all the useful content u had
@rasmic
@rasmic 4 месяца назад
Happy to hear that!
@MarcoPredari
@MarcoPredari 4 месяца назад
Keep going bro! You are doing awesome content.
@rasmic
@rasmic 4 месяца назад
thanks g
@MandeepSK-p9r
@MandeepSK-p9r 4 месяца назад
that unpaid line got me ! in fact my first internship was unpaid but currently doing a paid, now looking for a full-time role.
@rasmic
@rasmic 4 месяца назад
Keep cooking my g
@_boki019
@_boki019 4 месяца назад
good stuff my guy, keep it going
@rasmic
@rasmic 4 месяца назад
my g ty
@ReuelTeodoro
@ReuelTeodoro 4 месяца назад
The tanstavk query hook is genius
@maksymdudyk1718
@maksymdudyk1718 4 месяца назад
Next.js is a King of forcefull caching! Why do you need React-query with Next.js at all?
@rasmic
@rasmic 4 месяца назад
there are some banger helper functions my g
@goncaloshred
@goncaloshred 4 месяца назад
Why not SWR?
@thezeeshannn
@thezeeshannn 3 месяца назад
hey bro thanks for this video i was struggling to connect react query and next js
@rasmic
@rasmic 3 месяца назад
Glad it helped
@julianrizo2857
@julianrizo2857 4 месяца назад
I have to tell you the tanstack + server actions is good for DX but bad for UX, server actions can't be runned in parallel so if you need to use useQuery twice at the same time it needs to wait until one is done to run the other. The solution could be api handlers but no good DX, so I think tRPC is the best
@fitimbytyci345
@fitimbytyci345 4 месяца назад
You read my thoughts bro, thats what I recently started doing once I understood that limitations of server actions. Another thing to keep in mind is that you can use pure functions if your api supports cookie based authentication. In that case, in client components, when you wanna send requests that are protected, you just pass credentials: “include”. Otherwise you need to use nextjs as proxy. As you mentioned, writing all those route handlers is hell, trpc seems to help with that.
@rasmic
@rasmic 3 месяца назад
100% right, forgot to mention this as a con but will be dropping a video soon talking about this!
@lemonaderock4009
@lemonaderock4009 4 месяца назад
I would also recommend prefetching a query on a server, and then pass it with Hydration Boundary
@rasmic
@rasmic 4 месяца назад
i need to play with that as well
@onlinenk13
@onlinenk13 4 месяца назад
✨ Very useful For the route API, it really makes sense to use webhooks, but we can also consider using them if our backend acts as an API. For server actions, I mainly use them for requests in server components, I avoid using them on client components because we don't have total control over sending the request. You can't cut a request made with an action server. So I think it's more interesting to use them only in server components. I think it's better to use api routes with axios or fetch (with react query of course) for client-side requests.
@rasmic
@rasmic 3 месяца назад
I actually have come to realize it's better to fetch directly in a server component than using a server action in a server component!!
@julienheng3880
@julienheng3880 4 месяца назад
Great video! Thank you! Btw what theme are you using for vsc?
@rasmic
@rasmic 4 месяца назад
theme is called nextjs
@unkownsiner
@unkownsiner 4 месяца назад
Fxcking Legend! Keep it up lad
@rasmic
@rasmic 4 месяца назад
thanks g
@justinlinn1810
@justinlinn1810 3 месяца назад
I’ll use API endpoints also I want to create an external API. At work we use keycloak as a auth provider then we have a Next app that handles all request to other apps. So I made API routes so clients could auth with keycloak via the CAS next app. Or if external teams need an endpoint. I’ll often do this with an internal server action then add it to the endpoint with extra checks that I don’t need internally.
@rasmic
@rasmic 2 месяца назад
niceee
@freemancharles2491
@freemancharles2491 4 месяца назад
Great! Tutorial man ❤🎉 Which software do you use for editing? 🙏 The mouse moves so smooth too
@rasmic
@rasmic 4 месяца назад
link in the description broski
@freemancharles2491
@freemancharles2491 4 месяца назад
@@rasmic Thanks man! 🤍
@eduardomoraesrigo4782
@eduardomoraesrigo4782 4 месяца назад
i love tanstack query aswell! Thanks for the video man obs: what theme do you use and what is the screen video recorder app? (cool and fluid animations)
@rasmic
@rasmic 4 месяца назад
thanks g theme: nextjs video recorder: link in description
@guustgoossens8644
@guustgoossens8644 4 месяца назад
I’m just getting started building my first project w supabase and clerk and this vid is amazing, thanks! Is this repo public by any chance? I would love to go through your repo and study the supabase and clerk server stuff.
@rasmic
@rasmic 4 месяца назад
yessir, check it out starter.rasmic.xyz/
@tomyamado
@tomyamado 4 месяца назад
Great video!
@rasmic
@rasmic 4 месяца назад
Glad you enjoyed it
@sawos1596
@sawos1596 4 месяца назад
Thanks alot...In my case, I only use APIs for cronjob or external website consume. Other than that I use server actions with zod validations and I would appreciate it if you drop a video on how to use tanstack query with server actions in client componenets
@rasmic
@rasmic 4 месяца назад
Gotchu
@afridiwhatever6220
@afridiwhatever6220 4 месяца назад
Great content Earned a sub
@rasmic
@rasmic 4 месяца назад
ty my g
@msp82
@msp82 4 месяца назад
Congrats! It's an excellent video! What about the cache layer benefit of using the extended fetch API from Next.js? I'm using API endpoints for webhooks like you and the GET method to take advantage of the fetch web API cache on the server components to prevent unnecessary database requests.
@rasmic
@rasmic 3 месяца назад
Going to mention that in the video, u do lose the caching... also I think its better to fetch in a server component vs a server action if page is server rendered
@oliversmall
@oliversmall 4 месяца назад
Boss man, I was wonderkng why you didn't mention passing the server action to the "action" attribute of a form tag and the button submits the form? This is how I understood server actions to work from the Vercel video they dropped when the feature released
@rasmic
@rasmic 3 месяца назад
yeah that's for forms, i still use react-hook-form hence why I do it this way
@falasefemi3344
@falasefemi3344 4 месяца назад
Ad usual good content 👌
@rasmic
@rasmic 4 месяца назад
appreciate u g
@primostasis
@primostasis 4 месяца назад
as long as you don't use the data outside the application ex - mobile / other web then server actions and react query is the best pattern
@rasmic
@rasmic 3 месяца назад
agreed
@taunado
@taunado Месяц назад
Love it. Creating a custom hook adds another step as you're still using an action to fetch the data, so is it's core purpose to add error handling in this situation?
@taunado
@taunado Месяц назад
Might as well just fetch the data using the server action and pass the userID? const PortfolioList = async ({ userId }: { userId: string }) => { const items = await fetchPortfolioItems(userId);
@taunado
@taunado Месяц назад
fetchPortfolioItems is the server action import { prisma } from "@/lib/prisma"; export async function fetchPortfolioItems(userId: string) { const items = await prisma.portfolioItem.findMany({ where: { userId }, select: { id: true, title: true, vimeoLink: true }, }); return items; } Interested to hear your insight
@Diego_Cabrera
@Diego_Cabrera Месяц назад
how do you solve CROS origin issues? Loved the video btw!
@sulaga7992
@sulaga7992 2 месяца назад
If document page access is restricted by authentication then what is the point of checking auth again inside getAllDocuments action function? thank you
@rasmic
@rasmic 2 месяца назад
better safe than sorry
@emiralabuga9451
@emiralabuga9451 7 дней назад
Hi, awesome video ty. Btw what is this vscode theme?
@chrisrudman3495
@chrisrudman3495 4 месяца назад
What software do you use for your screen recording with the webcam overlay in the squircle?
@rasmic
@rasmic 4 месяца назад
the link is in my description g
@chrisrudman3495
@chrisrudman3495 4 месяца назад
Thanks looks exactly what I was after
@chrisrudman3495
@chrisrudman3495 4 месяца назад
Actually that was quite rude of me… I didn’t even mention your video itself. I thought it was very interesting and useful. Thanks for making this content. 🤘
@jairseedorf
@jairseedorf 4 месяца назад
You can actually remove the "use server" flag from your server actions that fetch data, because they are server components by default. Plus removing the flag turns all data fetching functions into GET requests instead of POST which is the default for server actions.
@gamingwolf3385
@gamingwolf3385 4 месяца назад
This is true , because this function is executed in server component so in the server , and always try as possible to fetch data in server components
@oliversmall
@oliversmall 4 месяца назад
Doesn't hurt to be verbose. There's a handful of functions that, if used in your component, make it client sided. So if you accidentally use those, it'll throw you an error right away
@rasmic
@rasmic 3 месяца назад
yes, should have mentioned that in a server component no need to add use server !!
@justin9494
@justin9494 3 месяца назад
server actions run sequentially, so if you have 2 requests being fired at the same time, the second request will wait for the first one to finish, and that is really bad. I think api routes are the best
@rasmic
@rasmic 3 месяца назад
yeah wouldn't use server actions in that case... probably just do calls in a server component still
@connect.tehseen
@connect.tehseen 4 месяца назад
Hey appreciate your videos man. What software do you use for recording?
@rasmic
@rasmic 4 месяца назад
In the description g
@BradySie-wo6vf
@BradySie-wo6vf 4 месяца назад
with client side fetching you can use useTransition instead of react query
@rasmic
@rasmic 4 месяца назад
tanstack query has way more helper functions I didn't go through that useTransition doesn't have
@MohdNisabAlam
@MohdNisabAlam 4 месяца назад
What theme youre using in vscode?
@rasmic
@rasmic 4 месяца назад
nextjs
@MauricioAndrian
@MauricioAndrian 4 месяца назад
How do you handle loading state from server actions triggered inside a button's onClick? At that point I believe you'll need react-query again and the fetching will occur client-side.
@rasmic
@rasmic 3 месяца назад
I use some ghetto state variables to track lol but i think there's a hook for it called useActionStatus
@Luisllaboj19
@Luisllaboj19 4 месяца назад
If you need some information only on the clientside would you collocate all the function logic inside of the custom hook /react query or would you ratther still create a server action to only be consumed on the client by that unique custom hook thats a react query wrappper?
@rasmic
@rasmic 3 месяца назад
unique custom hook thats a react query wrapper is my goto
@iuliancarnaru954
@iuliancarnaru954 4 месяца назад
Gold info 👏
@rasmic
@rasmic 4 месяца назад
Glad it was helpful!
@bigupbig2198
@bigupbig2198 2 месяца назад
But which is better? Let’s say I have a dynamic endpoint? Is sever action faster? Or just cleaner
@rasmic
@rasmic Месяц назад
if ur fetching data avoid server actions... use an endpoint... watch my updated videos
@israeloduguwa
@israeloduguwa Месяц назад
A lot of developers bash Nextjs like its a bad framework and hard to maintain. Lol😅, its because they are treating it like a server its ment for client side. You'll need a separate backend to make the most of Nextjs
@samuelvalentine7846
@samuelvalentine7846 4 месяца назад
Does using supabase in a component like navbar that shows throughout the application not make whole route a dynamic route?
@rasmic
@rasmic 3 месяца назад
No, dynamic routes are routes that change based on some param (e.g., /user/:id)
@nikelborm
@nikelborm 4 месяца назад
What's the vs code theme you are using?
@rasmic
@rasmic 4 месяца назад
it's called nextjs
@ChikiCodes
@ChikiCodes 2 месяца назад
arent server actions meant for post requests?
@rasmic
@rasmic 2 месяца назад
peep this new vid: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ZDxuDbY7ZOY.html
@IAmGamers-Official
@IAmGamers-Official 4 месяца назад
The name of the theme you are using?
@rasmic
@rasmic 4 месяца назад
theme is called nextjs
@IAmGamers-Official
@IAmGamers-Official 4 месяца назад
@@rasmic sorry, I mean your vs code theme
@rasmic
@rasmic 4 месяца назад
@@IAmGamers-Official yes, it's called nextjs :)
@Sahil.1
@Sahil.1 Месяц назад
Please make a beginner friendly crud tutorial with next clerk and supabase
@SUNGWONG5
@SUNGWONG5 4 месяца назад
server action will easy to move API to another framework like express.js
@rasmic
@rasmic 3 месяца назад
is this a question or statement my g?
@kingsleykelechionwuchekwa7508
@kingsleykelechionwuchekwa7508 4 месяца назад
Why are you using server actions to perform GET operations in a server component? Can't you just run the logic inside the server component? I believe server actions should be used for mutations if in server components.
@rasmic
@rasmic 3 месяца назад
100% correct, i dont need to do a server action in a server component... missed that in the video... going to record another soon!
@amershboul9107
@amershboul9107 4 месяца назад
Thanksssss!!
@rasmic
@rasmic 4 месяца назад
np g
@benmradbilel2177
@benmradbilel2177 4 месяца назад
100% agree
@rasmic
@rasmic 4 месяца назад
great minds think alike
@benmradbilel2177
@benmradbilel2177 4 месяца назад
❤@@rasmic
@ALVIERIDEVELOPER
@ALVIERIDEVELOPER 4 месяца назад
Bro how your machine so fast and smooth
@rasmic
@rasmic 4 месяца назад
MacBook i guess??
@johndevnoza4223
@johndevnoza4223 4 месяца назад
Yes but i use tanstack query for serverside not for client.
@rasmic
@rasmic 3 месяца назад
need to check that out
@maksymdudyk1718
@maksymdudyk1718 4 месяца назад
Next.js is a King of forcefull caching! Why do you need React-query with Next.js at all?
@rasmic
@rasmic 4 месяца назад
there are some banger helper functions
@maksymdudyk1718
@maksymdudyk1718 4 месяца назад
@@rasmic If you are talking about RQ's `isLoading`, Nextjs has it out of the box.
@rasmic
@rasmic 4 месяца назад
@@maksymdudyk1718 brother there is a lot more than isLoading lol
@maksymdudyk1718
@maksymdudyk1718 4 месяца назад
@@rasmic I think, you are right. And I was wrong.
@bagusadlann
@bagusadlann 3 месяца назад
​@@rasmiccan you give me an example sir? i'd say thank you
@dhruvverma1001
@dhruvverma1001 4 месяца назад
Can we get this code, looks golden all over
@rasmic
@rasmic 3 месяца назад
gonna create a more complete video + code soon so stay subbed for that
@nikhilpsathyanathan
@nikhilpsathyanathan 4 месяца назад
I follow the same methods
@rasmic
@rasmic 4 месяца назад
my g
@agustingarcinuno4172
@agustingarcinuno4172 4 месяца назад
Bro what theme is this
@agustingarcinuno4172
@agustingarcinuno4172 4 месяца назад
Should’ve read comments first my b fam
@rasmic
@rasmic 4 месяца назад
u good g lol
@xGalasko
@xGalasko 4 месяца назад
why does your mouse move that way 😭
@rasmic
@rasmic 4 месяца назад
the recording software I use does it
@Tanner-cz4bd
@Tanner-cz4bd 4 месяца назад
Trpc bro
@rasmic
@rasmic 4 месяца назад
mehhh
Далее
Modern Data Fetching in React (Complete Guide)
16:41
Просмотров 59 тыс.
Wait for it 😂
00:19
Просмотров 3,4 млн
МЭЙБИ БЭЙБИ - Hit Em Up (DISS)
02:48
Просмотров 397 тыс.
ДУБАЙСКАЯ ШОКОЛАДКА 🍫
00:55
Просмотров 1,4 млн
Fetching Data Doesn't Get Better Than This
6:58
Просмотров 128 тыс.
It's finally out!!! (Next.js 15 breakdown)
30:06
Просмотров 77 тыс.
Why I Still Use React Query with Next 14
11:28
Просмотров 66 тыс.
How To Learn A New Programming Language
6:24
Просмотров 272 тыс.
You might not need useEffect() ...
21:45
Просмотров 167 тыс.
Why is Vite Everywhere? | Evan You
38:32
Просмотров 35 тыс.
10 common mistakes with the Next.js App Router
20:37
Просмотров 223 тыс.
Wait for it 😂
00:19
Просмотров 3,4 млн