Hi this tutorial is really explanatory and can be understand well than other video on the same topic. There is a miner suggestion i want to add that it will be more beneficial to have a get or fetch data actions too.
Hi there! Firstly, thank you so much for the informative video on server actions. I've learned a lot from it! I just noticed in the code on page.tsx, there's an unused addExpense function. Since we've already separated the form into its own component and created a dedicated action for server interactions, it seems like this function isn't necessary anymore. Perhaps we could consider removing or commenting out this function to avoid confusion and keep our codebase clean. Just a suggestion to streamline things further! Thanks again for the awesome tutorial! Looking forward to more content from you. 😊
Hi, this is pretty straightforward but in the end your writing a function that accesses the database. If you write an API, you can reuse the endpoint as needed. aside from not exposing the POST to the client side how does this benefit the developer ? You're writing the function either way, right?
Hey Brett, awesome Video. How do we go about using server actions for calling external APIs where we have to authenticate ourself with headers (using clientid,secret). Do we just use fetch or can we use external libraries like axios inside server actions? In a lot of explanations we use forms and call our own database using ORMs like prisma, but never external apis. Another thing (more directed towards server components) is that it is often very confusing switching from one to another and use them simultaneously, when you can only use states inside client components or async/await inside server components.
Great video! I am having trouble finding a resource on how to redirect the user to another page after submitting to the database inside a server action. My code is similar to yours but I have a form with a lot of fields. redirect() says it works but isn't working inside a try/catch block and outside of the block says it's unreachable code 😬
How can we use server actions client side but outside of form tags, let's say I don't have any input form like calling a server action on click of a add to cart button, and also how to show loading state in that.
I recommend using API routes instead of server functions for that and only way to show loading state is with client side code. You will have to refactor code to suit your case
I wish there was a way to sort of see the cache working in action. Like with react query. Right now we just sort of assume everything works and is safe.
Yea that would be pretty cool but I guess you can test it out by adding new data and make sure you are fetching data by caching and see if the data updates or not
You don't have to place the cursor on the far right to make a new line, just hold ctrl and enter, you can be anywhere on the line. Same goes for new line above with ctrl+shift+enter. 😊
Thanks for watching! And I think you can only user server actions on forms for data mutations. If you want to perform a GET request then you should just use a route handler.
Thanks for sharing!. I have a question. Why does the title text flash when you add the school supplies? Edit: I found the answer in a github discussion, "I just noticed that the jitter is only there in dev mode. After building the project, it's gone."
My main issue with this is that, i can't know if the server action succeeds or fails, what if the user doesn't have a good network?...i have to use a form everytime I want to use server actions, what if i want it on a click of a button?, id rather just stick to creating APIs and making client side requests
I agree with you, I still mainly use API endpoints and only really user server actions on contact forms at the moment. However, things could always change.
I hope Nextjs team sees the struggle with the use of server actions and come up with brighter ideas, its really beautiful not to have to create and API endpoint for every action, but it also comes with consequences@@brettwestwooddeveloper
Hi, i am self-taught and I've started learning Next.js 13 2-3 months ago, i have learned how to create simple full-stack app, where app communicates to DB via prisma ORM in/api folder's routes. I liked that way, allowed me to separate backend codes from frontend, but now i see Next.js 14 and Server Actions on every corner. What does that mean for me? Should i stop using /api folder way, and start using server actions, or can i still use /api folder way? Thinking of server actions as newer way, as a part of latest version of Next.js, server actions are probably recommended way. It is a big change for me, who did not learn Next.js completely, yet i need to change big part of how i managed db stuff in my app. Thanks to Your video i am starting to understand server actions, thank you. :}
@@brettwestwooddeveloper and it would be really helpful if you do tutorial on a large scale project (like may be a million of users ).. like how should we proceed about it. what will be the best practices when we use next 14. how will be the folders structure architecture.. like a boilerplate kinda thing.. I guess nany of us get understanding in small scale app. but get stuck in architecture wise while going for building large-scale application.
i still dont like this idea, just refetch everything, you can have some weird behaviors.. lets say that i have a "big" system where 2 users or more can add the data at the same time, the refetch will bring the new items which i didnt create. the optimistic way where you can just push to your state its better
Bro's knoweledge of react : 9.5 Bro's knoweledge of basic windows: 1 Lol unless you code in mac or linux I dont understand how is it that you look like my grandma trying to use the computer when moving stuff around the screen
Too much over engineering just to use server actions. I don't think I will be using it. Please viewers don't swallow any new release that comes up, just take a little taste of it and throw it out.
@@dawid_dahl your statement tells you don't know what is happening in the developer community. Server actions is fucked when you are using the same API for mobile app development.
As a beginner, I can say that reading the Nextjs docs is overwhelming but when they get explained - like you did. It makes perfect sense.
Thank you so much! I tried my best to explain it
This is the best explanation I have watched so far, you have earned a new subscriber. Thanks!
Awesome! Thank you! Glad I could help you out!
Perfect explanation about the server actions.
Thank you!
Hi this tutorial is really explanatory and can be understand well than other video on the same topic. There is a miner suggestion i want to add that it will be more beneficial to have a get or fetch data actions too.
Never seen a better explanation than this 💯
Very nice and concise tutorial! I learned a lot from it. 👍
Thanks! Glad it was helpful!
very useful and explained in super easy way. Much appreciated!
Amazing, it all makes sense now.
Awesome! Glad I could help you out!
Thanks for sharing Brett.
You are welcome!
Sharing is caring.
But when I shared something with Brett. Bro got angry at me and is not talking to me now😢
Well done. Keep up the good work!
Thanks, will do!
Wow. You explained it all. Thx
No problem! Thanks for watching my content!
Good Video Awesome Explanation
Thank you!
God bless, Brett
Thank you!
You always know what we need
Glad I could read your mind
I found my friend the best in the word and while sharing the best thing with him he stopped talking to me and now😢
now i really understand the server-actions, very well tutorial thanks a lot ❤
No problem! Thank you for watching!
Great video thanks man!
Thank you!
Hi there! Firstly, thank you so much for the informative video on server actions. I've learned a lot from it!
I just noticed in the code on page.tsx, there's an unused addExpense function. Since we've already separated the form into its own component and created a dedicated action for server interactions, it seems like this function isn't necessary anymore.
Perhaps we could consider removing or commenting out this function to avoid confusion and keep our codebase clean. Just a suggestion to streamline things further!
Thanks again for the awesome tutorial! Looking forward to more content from you. 😊
No problem! Thanks for the support and appreciate the feedback!
Your explanations are always awesome. Just waiting for some full-stack videos from you 😁
Glad you like them! Should be coming soon
Thank you so much. Been struggling with the App router
No problem! Glad I was able to help you out!
Best explanation hands down!
Thank you so much!
I have no experience explaining anything 😢 so I lost my friend while explaining him something really very important.
Great explanation. Thank you!
Glad it was helpful! No problem!
Hi, this is pretty straightforward but in the end your writing a function that accesses the database. If you write an API, you can reuse the endpoint as needed. aside from not exposing the POST to the client side how does this benefit the developer ? You're writing the function either way, right?
Really good video!!! Thx
Thank you and no problem!
Hey Brett, awesome Video.
How do we go about using server actions for calling external APIs where we have to authenticate ourself with headers (using clientid,secret).
Do we just use fetch or can we use external libraries like axios inside server actions?
In a lot of explanations we use forms and call our own database using ORMs like prisma, but never external apis.
Another thing (more directed towards server components) is that it is often very confusing switching from one to another and use them simultaneously, when you can only use states inside client components or async/await inside server components.
What extension do I need to use for function autocomplete suggestion like you have here? 2:58
Github Copilot. It does cost a monthly fee of like $10/mo
Great video! I am having trouble finding a resource on how to redirect the user to another page after submitting to the database inside a server action. My code is similar to yours but I have a form with a lot of fields. redirect() says it works but isn't working inside a try/catch block and outside of the block says it's unreachable code 😬
Appreciated. 0:14
How can we use server actions client side but outside of form tags, let's say I don't have any input form like calling a server action on click of a add to cart button, and also how to show loading state in that.
I recommend using API routes instead of server functions for that and only way to show loading state is with client side code. You will have to refactor code to suit your case
prisMA!!
thanks for the video
No problem!
Man, thanks!
You are welcome!
I wish there was a way to sort of see the cache working in action. Like with react query. Right now we just sort of assume everything works and is safe.
Yea that would be pretty cool but I guess you can test it out by adding new data and make sure you are fetching data by caching and see if the data updates or not
What setting or extension do you have enabled to see the vertical ruler on the side, showing opening and closing of divs?
You don't have to place the cursor on the far right to make a new line, just hold ctrl and enter, you can be anywhere on the line. Same goes for new line above with ctrl+shift+enter. 😊
Thank you for the tip, will definitely have to get use to it
Thanks for this great tutorial.
I have a question. Can't we fetch data by using server actions without forms like we do GET request using api route?
Thanks for watching! And I think you can only user server actions on forms for data mutations. If you want to perform a GET request then you should just use a route handler.
I haven't found anything about this in the docs, but can you actually access the request object?
Very nice. Good to know
Good work
Thank you
Excellent!!!!!!!!!
is there a link to a github repo :) sometimes this helps to see the whole example at the end?
Thanks for sharing!. I have a question. Why does the title text flash when you add the school supplies? Edit: I found the answer in a github discussion, "I just noticed that the jitter is only there in dev mode. After building the project, it's gone."
No problem! Thanks for the sub!
How do you handle errors or server side validation?
You can use a package like ZSA which does server side validation. There are other ways as well
On the form component, could i just import useState instead of useRef to reset the fields? I’m not that familiar with useRef. Great video by the way
Thank you! And yes you can use useState hook as well to reset the form.
Yes, absolutely useState can be used.
But it is better to use useRef for better performance, refer to re-rendering in react useState.
Hello, how will realize form validation?
Use zod or something similar
When you add the expense, looks like the page is refreshing, right? that's not good.
Great vid, thank you!
You are welcome!
My main issue with this is that, i can't know if the server action succeeds or fails, what if the user doesn't have a good network?...i have to use a form everytime I want to use server actions, what if i want it on a click of a button?, id rather just stick to creating APIs and making client side requests
I agree with you, I still mainly use API endpoints and only really user server actions on contact forms at the moment. However, things could always change.
I hope Nextjs team sees the struggle with the use of server actions and come up with brighter ideas, its really beautiful not to have to create and API endpoint for every action, but it also comes with consequences@@brettwestwooddeveloper
nice video
Thank you
Hi, i am self-taught and I've started learning Next.js 13 2-3 months ago, i have learned how to create simple full-stack app, where app communicates to DB via prisma ORM in/api folder's routes. I liked that way, allowed me to separate backend codes from frontend, but now i see Next.js 14 and Server Actions on every corner. What does that mean for me? Should i stop using /api folder way, and start using server actions, or can i still use /api folder way? Thinking of server actions as newer way, as a part of latest version of Next.js, server actions are probably recommended way. It is a big change for me, who did not learn Next.js completely, yet i need to change big part of how i managed db stuff in my app. Thanks to Your video i am starting to understand server actions, thank you. :}
I would still stick with API folder routes. It is better overall in my opinion anyways.
Revalidate tag how to use
I talk about how to use the Revalidate tag at 7:26 mark
@@brettwestwooddeveloper revalidate tag not revalidatepath
That will show error "only plain objects can be passed to the client component"
thank you
why do you call it prism when your clearly writing prismA (love the video learned alot)
hahaha speech impediment
github link please
sorry don't have for this. It's more of a tutorial
@@brettwestwooddeveloper and it would be really helpful if you do tutorial on a large scale project (like may be a million of users ).. like how should we proceed about it. what will be the best practices when we use next 14. how will be the folders structure architecture.. like a boilerplate kinda thing.. I guess nany of us get understanding in small scale app. but get stuck in architecture wise while going for building large-scale application.
It is impossible to have rent for 800$. Other than that, nice video. Thank you!
Its definitely possible
Maybe it's easier, but you send more code and other things to the client = more code = more traffic + more insecure
i still dont like this idea, just refetch everything, you can have some weird behaviors.. lets say that i have a "big" system where 2 users or more can add the data at the same time, the refetch will bring the new items which i didnt create.
the optimistic way where you can just push to your state its better
Bro's knoweledge of react : 9.5
Bro's knoweledge of basic windows: 1
Lol unless you code in mac or linux I dont understand how is it that you look like my grandma trying to use the computer when moving stuff around the screen
hahahah yea probably honestly.
bro you look ai generated
Too much over engineering just to use server actions. I don't think I will be using it. Please viewers don't swallow any new release that comes up, just take a little taste of it and throw it out.
True, I prefer standart front to back communications with API, mutating data
One can really tell you don’t have a clue what you are talking about.
I partially agree with you but yea I think overall I will be sticking with API folder routes.
@@dawid_dahl your statement tells you don't know what is happening in the developer community. Server actions is fucked when you are using the same API for mobile app development.
@@therealdevopsintern Why don’t you provide some arguments instead of just swearing and acting like an idiot?