When to use server actions in Next JS 14

  Рет қаралды 9,367

WebDevEducation

WebDevEducation

Күн бұрын

Пікірлер: 26
@WebDevEducation
@WebDevEducation 8 ай бұрын
Let me know if I've forgotten any scenarios!
@glengal6490
@glengal6490 2 ай бұрын
Concise and proper. Just as I wanted. Thanks a bunch
@WebDevEducation
@WebDevEducation 2 ай бұрын
Glad it helped!
@omarkraidie
@omarkraidie Ай бұрын
can you should you use server actions with tanstack query for reladiating and handling caching / loading and errors?
@Skillthrive
@Skillthrive 5 ай бұрын
Another one I came across is when the payload would be over 1MB because that's what server actions are limited to.
@b166er4
@b166er4 7 ай бұрын
i use it as you ... just i try to never fetch data in client component... as it is possible, always fetch in async page and pass data as props to client components ...
@jovanjevtic1620
@jovanjevtic1620 8 ай бұрын
So, if I already created a website with nextjs and server actions and want to build a mobile app, I should then create api routes for all those server actions to cover same functionality in mobile app? (or whole another express server)
@WebDevEducation
@WebDevEducation 8 ай бұрын
Yes that's correct 👍
@dreamsachiever212
@dreamsachiever212 8 ай бұрын
​@@WebDevEducation I had the same question. I am building a listing directory web app with nextjs and would like to build the mobile version of it using expo. Is it a best practice to use route handlers for the webapp and tanstack query for instance for the mobile app?
@WebDevEducation
@WebDevEducation 8 ай бұрын
Yes it sounds like you'd want to use route handlers for this scenario which can be called from anywhere (within your next app or from an external web / mobile app). Thinking about it though, I might still use server actions for the next app (because a lot of the time server actions tend to be a bit more granular and less RESTful), and create a more RESTful API using route handlers for the mobile app (or any other external app). That way you could fully optimise your next app rather than being tied into a more RESTful API which might not be optimised for the way your next app needs to fetch its data. TLDR; I'd use server actions for the next app, and create separate API endpoints / route handlers for any external apps.
@dreamsachiever212
@dreamsachiever212 8 ай бұрын
@@WebDevEducation Thanks for the insights. Really appreciate. I thought I would be locked in an either-or situation, but glad to know I can still use sever actions for the web app. Thanks again
@iancarr3923
@iancarr3923 8 ай бұрын
Very useful, thanks.
@adarshrathi8265
@adarshrathi8265 7 ай бұрын
i want suggestion this type of examples const onSubmit = async (values: z.infer) => { try { const url = qs.stringifyUrl({ url: "/ api /channels", query: { serverId: params?.serverId } }); await axios.pos t(url, values); form.reset(); router.refresh(); onClose(); } catch (error) { console.log(error);, in server action how we manage StringifyUrl, any idea, because it create me a lot trouble.
@umer8509
@umer8509 8 ай бұрын
Can we use server action in next if we have a backend in laravel?
@WebDevEducation
@WebDevEducation 8 ай бұрын
Server actions can only be called from within a next app.
@TabuHana
@TabuHana 8 ай бұрын
this is self explanatory i feel, but nice vid
@nasko235679
@nasko235679 3 ай бұрын
Here's the confusing part. For me the most difficult thing about fetching data is being able to SECURELY fetch data from a client component and by securely I mean authenticating/authorizing the user first. With Server Actions that becomes extremely easy because you can do the authentication check inside the server action itself. HOWEVER in nextjs docs they've explicitly said that server actions are meant for data mutations and they are all POST requests, also AFAIK they get queued so you can't execute them asynchronously (?). That's why I've been using route handlers for fetching from client components, and when I need to fetch in server components I just use helper functions without the "use server" directive and I execute those at the top of the server component. Thoughts?
@zedquach
@zedquach 3 ай бұрын
You can use useTransition for calling server action that fetch. But generally I would use server component for data fetching
@liangfamily
@liangfamily 8 ай бұрын
Awesome! It’d be great if you follow up with code examples in the future
@AlexanderBelov-y8o
@AlexanderBelov-y8o 8 ай бұрын
Thank you for the amounts of valuable knowledge you put out for free!
@WebDevEducation
@WebDevEducation 8 ай бұрын
You're welcome 😊🙏
@donaminos
@donaminos 22 күн бұрын
Thanks a lot for your insights. I am trying to wrap my head around server actions, and I have a question related to the scenario of fetching data in a client component. From my understanding server actions always use the "POST" method for the request sent to the backend. And using a "POST" request to fetch data, feels wrong to me. It should be a GET. Using a server action in this scenario goes against the initial intent of this feature (data mutation) I guess, doesn't it ?
@WebDevEducation
@WebDevEducation 21 күн бұрын
Yes you're right, altho I'd be fetching data in a server component before doing that, and passing it down to the client component if it needed to be passed down rather than directly fetching from the client component.
@richardmacarthy8569
@richardmacarthy8569 4 ай бұрын
Tom, my main man! How's it going? Long time no see haha. Thanks for the pointers. Much love x
@WebDevEducation
@WebDevEducation 4 ай бұрын
Haha no way Richie Mac! All good here man hope things are well with you!
@u-def
@u-def 8 ай бұрын
I didn't event think that server action doesn't support streaming, So I was wondering what is the differences when I saw the title of your video. But this video really informative and not unneccessary long. Thank you KZbin tells me this channels.
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 215 М.
Релиз NextJS 14 и Server actions
17:53
Михаил Непомнящий
Рет қаралды 16 М.
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19
LIFEHACK😳 Rate our backpacks 1-10 😜🔥🎒
00:13
Diana Belitskay
Рет қаралды 3,9 МЛН
From React to React Native in 12 Minutes
12:33
Simon Grimm
Рет қаралды 17 М.
How To Use Next.js 14 Server Actions
21:06
Brett Westwood - Software Engineer
Рет қаралды 25 М.
React + Servers = Confusion
20:30
Theo - t3․gg
Рет қаралды 42 М.
Don't Make These Next.js Mistakes
13:01
Dave Gray
Рет қаралды 23 М.
I Didn't Know Next.js Server Actions Could Do This!
6:53
James Q Quick
Рет қаралды 4,8 М.
The Problem with React Server Actions
9:45
Josh tried coding
Рет қаралды 20 М.
Next JS forms with Shadcn UI (the EASY way)
28:00
WebDevEducation
Рет қаралды 45 М.
Next.js Server Actions...  5 awesome things you can do
7:51
Beyond Fireship
Рет қаралды 271 М.
5 Tips and Tricks To Make Your Life With Next js 14 Easier
17:11
developedbyed
Рет қаралды 39 М.
All 29 Next.js Mistakes Beginners Make
1:45:10
ByteGrad
Рет қаралды 129 М.