Тёмный
No video :(

A ToDo List with  

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

Let's build a dynamic ToDo List with NextJS Server Actions and learn more about why the UI might flash and how the caching can be controlled.
This is the follow-up to my other video ( • 🤯 NextJS Server Action... ) about #nextjs13 Server Actions.
The GitHub Repo: github.com/act...
Sources:
- nextjs.org/doc...
- nextjs.org/doc...

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

 

10 май 2023

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 34   
@kacpermakingsoftware1447
@kacpermakingsoftware1447 8 месяцев назад
This is absolutely fantastic, just starting my adventure with Next.JS and React and you've saved me at least a few hours of research. Thanks!
@codinginflow
@codinginflow Год назад
Tip: If you wanna revalidate the page on every refresh but don't use fetch, you can "export const revalidate = 0" from the file of that page instead
@activenode
@activenode Год назад
Yup, that's an alternative 👍
@ranchpanda3530
@ranchpanda3530 Год назад
Your vids are awesome. hope your channel will grow fast!
@activenode
@activenode Год назад
Thanks so much! Means a lot.
@codinginflow
@codinginflow Год назад
I don't understand the point of the useTransition here. What would be different if you removed it?
@activenode
@activenode Год назад
Nice question. When mutating Data on the Server and hence forcing NextJS to refresh parts of the Page then useTransition is indicating that change. This might sound redundant first but the underlying technique can unblock the UI. react.dev/reference/react/useTransition#marking-a-state-update-as-a-non-blocking-transition But explaining that would probably take a full Video 🤗
@activenode
@activenode Год назад
Tldr: useTransition is required as per NextJS Docs in such a case but that doesn't mean it wouldn't work otherwise nextjs.org/docs/app/building-your-application/data-fetching/server-actions#custom-invocation-using-starttransition
@codinginflow
@codinginflow Год назад
@@activenode But you're not awaiting the server action, so why would it cause a block in the UI?
@activenode
@activenode Год назад
@@codinginflow Very good question mate! This is really difficult to explain in a few comments a s startTransition isn't one of the easiest hooks to get into. I have made a full video about this hook only but in a different language / different platform. If I find the time I might make one on YT as well :). useTransition doesn't require "async" functions per se. It's a React Hook that does basically something like "flush()" when data is being set. Checkout this high-level sample here: blog.webdevsimplified.com/2022-04/use-transition/ There's also no async function inside. Sure, I get the point, you are saying we are calling a Promise which is basically "thrown" and left alone so it won't block the UI like maybe the version in that link does. But: NextJS Docs are requiring exactly this "You mutate data with a Server Action explicitly -> You SHOULD use useTransition". Which extremely likely has something to do with the fact that NextJS uses code which benefits of this. For now I suggest 2 things: - Get deeper into useTransition if that's of interest - Do what the Documentation says to avoid future collisions or unwanted side-effects Cheers Mate!
@codinginflow
@codinginflow Год назад
​@@activenode Thank you for your writing this 👍 You're a nice guy
@foreach1
@foreach1 Год назад
Just found your channel, goldmine!
@activenode
@activenode Год назад
Thanks mate
@lightninginmyhands4878
@lightninginmyhands4878 Год назад
fantastic. I'd like to see a video on server components and fetching with those, if you have any insights about them
@activenode
@activenode Год назад
can you specify? Fetching and returning that data from the Action?
@alsherifkhalaf7385
@alsherifkhalaf7385 Год назад
Thanks 👍
@activenode
@activenode Год назад
Always welcome :)
@Happyday-nn6rh
@Happyday-nn6rh Год назад
very helpful
@eliashami1977
@eliashami1977 Год назад
Thank you for this video it's helpful. Quick question, why are you calling an API inside your server component to fetch data ? Why not just get the data directly?
@activenode
@activenode Год назад
Good Question! The API basically is a "simulation" as if you are using external data providers. If you don't have external APIs this isn't the use-case I am showing :)
@activenode
@activenode Год назад
So the only reason there is a Server INSIDE is to simulate as if the server was "outside" (e.g. because you have a "static" page with dynamic data from an external provider, Firebase, Supabase, etc)
@marc-andrewelie7684
@marc-andrewelie7684 Год назад
Hey can you do a video about uploading files to a database? Something like Microsoft SQL Server?
@activenode
@activenode Год назад
NextJS to SQL Server? Most of the time people don't want files _inside_ of the databases rather than on a file system. Is there good reasons to do so? Just hit me up with a bit more info
@OnlyJavascript
@OnlyJavascript Год назад
so..we don't need react query anymore?
@activenode
@activenode Год назад
Theoretically, yes. However they can be combined like a good team
@eminvesting
@eminvesting Год назад
I'm not sure why you didn't place your server actions directly in the form component? why did you go through all of this mess instead of just putting the server actions right in the addtodoform component and simply use the component in your layout without passing props around etc
@activenode
@activenode Год назад
Hey, thanks for the comment, appreciated. As always in Software Engineering and Architecture there are many ways to achieve something. I have 2 videos about server actions. This one, in which I wanted to also show how to manually call those actions (which I felt important for an overall understanding especially for newcomers) and the other one in which I show the more pure and also progressive way (as stated at the end of this video). But the tl;dr is: Depending on your given architecture the component might not be the one knowing about the logic e.g. in a interdisciplinary team - which is a common case in corporate design systems e.g. Also you cannot make a Server Component which will do "e.preventDefault()" in the onSubmit as part of the form. But many want to validate in the client as well for better UX. So whilst what you are proposing will definitely work as well (considering its limitations) I went for this way to show a more complex interaction with the goal of providing a broader understanding. Often, when teaching just in a very scoped context, people do not get the "ah, this you can do as well" effect.
@activenode
@activenode Год назад
Here is the link to the documentation that Server Action definitions are not allowed in Client components: nextjs.org/docs/app/building-your-application/data-fetching/server-actions#usage-with-client-components Happy to hear further questions. Rock on!
@eminvesting
@eminvesting Год назад
@@activenode so whenever you want to have some client-side JavaScript the old React way you gotta make the whole component a client component and pass the server actions as props. Makes sense . I think I get it now, thank you ^^
@caiohenrique1624
@caiohenrique1624 Год назад
Theme?
@activenode
@activenode Год назад
It is really just a bit of tailwind and this background: `background-image: linear-gradient(to top, #5f72bd 0%, #9b23ea 100%);`
@caiohenrique1624
@caiohenrique1624 Год назад
@@activenode vscode theme :c
@activenode
@activenode Год назад
@@caiohenrique1624 Beautiful Dracula Darker i think
@TightyWhities94
@TightyWhities94 Год назад
So much complexity just to make the framework do the simplest things. I think Vercel doesn't know what they're doing at this point. They're creating more problems for every problem they fix. I can't believe people are excited for these new updates. Really disappointed where the front end world is headed.
Далее
The Story of Next.js
12:13
Просмотров 562 тыс.
Understand the Supabase SSR Package easily
13:55
Просмотров 11 тыс.
I forced EVERYONE to use Linux
22:59
Просмотров 334 тыс.
Turns out REST APIs weren't the answer (and that's OK!)
10:38
tRPC + NextJS App Router = Simple Typesafe APIs
19:18
What Next.js doesn't tell you about caching...
13:32
Просмотров 11 тыс.
Server Actions: NextJS 13.4's Best New Feature
21:41
Просмотров 60 тыс.
How NextJS REALLY Works
28:25
Просмотров 143 тыс.