Тёмный
No video :(

🤯 NextJS Server Actions - never write Post Requests again 

activenode
Подписаться 2,2 тыс.
Просмотров 10 тыс.
50% 1

The #NextJS project has gotten a lot of new features with 13.3+ and 13. But there is one thing that caught my special attention: NextJS Server Actions.
In the good old PHP times people were trying to build similiar things by parsing the provided templates into some automagic.
NextJS is inspired by the best of PHP, Ruby on Rails and last but not least it's very apparent idol: Remix. NextJS is adapting to become a better Remix.
React SSR is now the de-facto standard.
Links:
nextjs.org/doc...
developer.mozi...
Credits:
A Little Night Dance by | e s c p | escp-music.ban...
Music promoted by www.free-stock...
Creative Commons / Attribution 4.0 International (CC BY 4.0)
creativecommon...
#webdevelopment #react #vercel

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

 

4 май 2023

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 50   
@gunasheelan4130
@gunasheelan4130 24 дня назад
found the life save i have been searching this for weeks thanks a bunch 😇😇
@neetdemon
@neetdemon 10 месяцев назад
I wasted all of yesterday trying to pass data from a Client Component to a Server Component. You just saved my ass. Thank you so much!!!! Also subscribed :) looking forward to more vids
@activenode
@activenode 10 месяцев назад
Thanks man! That's the kind of comments I'm making videos for :)
@arandomguythatdoesntpost
@arandomguythatdoesntpost Год назад
very cool, thank you for explaining this! ❤
@jgturner29
@jgturner29 Год назад
Can you build out the validation with error message on client side would like to see this video continued...👍👍
@kemekenneth
@kemekenneth 5 месяцев назад
Thanks for the video. Now this gets me thinking, can I preventDefault, validate the inputs, then call server action?
@activenode
@activenode 5 месяцев назад
Yes, you can!
@hrithikvishwakarma001
@hrithikvishwakarma001 Год назад
Great 🎉
@parkerrex
@parkerrex Год назад
yesssssss
@LtTheXamax
@LtTheXamax Год назад
Thanks, unfortunately, in my project the data was not passed true the components, I'm using latest version and added the experimental thing. :/
@activenode
@activenode Год назад
Do you have a sample link / codebox?
@LtTheXamax
@LtTheXamax Год назад
@@activenode Never mind, I made it work with useTransition. Man, you saved my life, I was trying make it work for 3 days and your video helped me a lot, please make more videos, you are great. Love you!
@activenode
@activenode Год назад
@@LtTheXamax Awesome! thanks so much 🙌
@sadiqpasha6622
@sadiqpasha6622 Год назад
So, if I understood correctly you’re saying that even if you a serve action from a client component it still works?
@activenode
@activenode Год назад
Yup because basically only a reference to that action is passed, not the action itself so to say.
@parkerrex
@parkerrex Год назад
subbed
@CheulongSear
@CheulongSear Год назад
I am new to this stuff. Could you show me how backend handle this?
@activenode
@activenode Год назад
Hey. Im working on more Videos 🙌
@user-xu1xb5iz5w
@user-xu1xb5iz5w 8 месяцев назад
is it possible in server actions that we can send body parameters in an object in POST method and fetch data
@activenode
@activenode 7 месяцев назад
Can you specify what you're trying to do? Cheers
@user-xu1xb5iz5w
@user-xu1xb5iz5w 7 месяцев назад
​@@activenodei have a api url in which i have to send some request body object through headers and then it give a data in the output in server actions this doesnt work but in axios method it works
@rayyanalam4815
@rayyanalam4815 Год назад
A question, was wondering if I should use this approach for sending a post request to my backend which is in python to calculate some stuff and get back the calculated result? Or should I just go with client side approach? I am very new to this and have trouble understanding which might be a better approach.
@activenode
@activenode 10 месяцев назад
It depends. Talking to your Python script can be done via NextJS Backend as both are Backend. If you have a Python only Backend being a Server in its own then you can also skip the NextJS Backend but also that removes the possibility of Server Action Usage
@stevebendersky2056
@stevebendersky2056 11 месяцев назад
How do I clean the fields such as setState with empty string after sending request?
@activenode
@activenode 9 месяцев назад
Sorry for the long wait, the comment didn't show in my dashboard. As you can see in the video, there is an onSubmit in combination with the action. In the onSubmit you can trigger the setState.
@user-xu1xb5iz5w
@user-xu1xb5iz5w 8 месяцев назад
how to send body parameter and fetch data in the server actions?
@activenode
@activenode 8 месяцев назад
I think for this you might be interested in the other video which shows how we can trigger server actions. Hope that answers your question? If not, just come back again :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-6TRwsu0mUps.html
@user-xu1xb5iz5w
@user-xu1xb5iz5w 8 месяцев назад
@@activenode im trying this but its not working import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { getServerSession } from "next-auth"; import React from "react"; interface Session { user?:{ data?: { access_token: string; }; } } export default async function fetchCount() { const session: Session = (await getServerSession(authOptions))!; const token = session?.user?.data?.access_token; console.log(token, 'ttt'); const res = await fetch('api-for-example.com ', { next: { revalidate: 0, }, method: "POST", body:JSON.stringify({ "stats": "current_user", "query_data": "yahoo.net", ..... }), headers: { "Cookie": `access_token=${token}`, "Content-type": "application/json", }, }); return await res.json(); };
@parkerrex
@parkerrex Год назад
can you add a video for using kysely and planetscale?
@activenode
@activenode Год назад
Noted, checking what can be done.
@thiccboi6211
@thiccboi6211 Год назад
While this is pretty cool and very useful in Next, its not new in JS frameworks or any other web frameworks because RPC's are a very old concept. I think it exists from the Visual basic days
@activenode
@activenode Год назад
Indeed! In general it's exciting to see that the tech world iterates including iterating back and forth. The only difference is the convenience it gets through optimal combination.
@LtTheXamax
@LtTheXamax Год назад
But the server actions reloads also styles and so on? Is there a way not to reload the styles?
@activenode
@activenode Год назад
Are you using mutations with Cache Revalidation in your Server Action? In my case, without, it didnt reload styles.
@LtTheXamax
@LtTheXamax Год назад
@@activenode yes I'm using mutations, how can I mutate data without reloading styles? The data is fetched via api.
@activenode
@activenode Год назад
@@LtTheXamax Server Actions are still in Alpha so there might be new stuff incoming that solves the problem of a "general style reload". There is potential workarounds. I might make an additional video for that.
@LtTheXamax
@LtTheXamax Год назад
@@activenode that would be great, can't wait!
@activenode
@activenode Год назад
@@LtTheXamax Hope this one helps ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-6TRwsu0mUps.html
@andreaswu7973
@andreaswu7973 Год назад
how to prevent empty form submit on the server?
@activenode
@activenode Год назад
Coming soon in my next video
@andreaswu7973
@andreaswu7973 Год назад
@@activenode looking forward to it!
@activenode
@activenode Год назад
@@andreaswu7973 Hope this one helps: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-6TRwsu0mUps.html In this video I am showing how to run actions manually and hence prevent the submission from client -> server. However: If your question was more related to: How to submit when no js is involved. (server-only) please tell me. I was thinking about getting deeper into server-only / progressive enhancements as well.
@andreaswu7973
@andreaswu7973 Год назад
@@activenode hey thanks for this. if you plan to make a series about server actions that'd be great!
@PIRAKAS666
@PIRAKAS666 Год назад
And what can we do with it? Would love to see a real world scenario.
@activenode
@activenode 7 месяцев назад
Hey, sorry for the late response, just seen it. The most common use-case is progressive enhancement (even though there's more). E.g.: You create a form with action=YourServerAction and it will both available on frontend (w/ JavaScript) and as well as a URL (without JavaScript on the Frontend). Even though, there's very few people disabling JavaScript, the reasoning behind it is that in our internet-everywhere world sometimes e.g. on the train, you can loose connection and the Frontend isn't loaded properly. Then backend will take over
@watb8689
@watb8689 Год назад
feels like asp all over again
@activenode
@activenode Год назад
Is that a good or a neutral feeling?
@heleneniederfischach1943
@heleneniederfischach1943 Год назад
Muss das immer in englisch sein???
@DrsHWolfenstein
@DrsHWolfenstein Год назад
Yes!
Далее
Understand the Supabase SSR Package easily
13:55
Просмотров 11 тыс.