2024년. NextJS 14를 배워야하는 이유.

노마드 코더 Nomad Coders
28 Jan 202406:12

Summary

TLDRIn this video, the speaker enthusiastically shares their experience upgrading to Next.js version 14, highlighting two groundbreaking features: server components and server actions. The speaker explains how these features enhance the development experience by significantly reducing the amount of code needed, improving app performance, and streamlining data handling without the need for an API. By leveraging server components and server actions, developers can now directly interact with databases and perform secure data mutations, respectively. The speaker also introduces a free 4-hour Next.js course and an updated comprehensive course on building a full-fledged Next.js application, emphasizing the practical benefits and efficiency gains from the latest Next.js features.

Takeaways

  • 😃 Next.js is a popular React framework for building fullstack web apps used by major companies like TikTok and Twitch
  • 🤓 Next.js 14 introduced server components and server actions which improve performance and developer experience
  • 👍 Server components let you render components only on the server which improves performance and security
  • 🔒 Server components allow connecting directly to databases without exposing secrets to client
  • ⚡️ Use 'useClient' to opt-in to browser rendering when you need interactivity or browser APIs
  • 🎉 Server actions let you handle data mutations directly without needing an API endpoint
  • 🧙‍♂️ Server actions automatically pass data between frontend and backend securely behind the scenes
  • 🛠 UseFormStatus and useFormAction hooks allow displaying status to user during mutations
  • 📈 Next.js 14 upgrades like server components can delete large amounts of code
  • 🎓 Free 4-hour course and paid Fullstack app course can teach you more about Next.js 14 features

Q & A

  • What is the main topic of the video script?

    -The video script is about the latest features of Next.js version 14, specifically server components and server actions.

  • What are the benefits of using server components in Next.js 14?

    -Server components allow developers to choose if a component should be rendered only on the server or not. This means the user doesn't have to download and render all the components of the application in the browser, reducing the amount of JavaScript code and allowing developers to delete a lot of code.

  • What is the significance of server actions in Next.js 14?

    -Server actions make the developer experience of data mutations, such as creating a user account, incredible. They allow developers to eliminate the need for an API endpoint and fetch code, and instead write the logic directly in the component. Next.js handles passing data between the component and action securely.

  • What are the hooks available for server actions in Next.js 14?

    -There are two hooks available for server actions: useFormStatus and useFormState. useFormStatus allows developers to know the state of the mutation and show the user a loading message or errors, while useFormState allows for more structured responses in case of errors.

  • What additional features of server actions are mentioned in the script?

    -Server actions have cool functions to revalidate data, check cookies, or even redirect the user when the mutation is finished.

  • What free resources are mentioned for learning Next.js?

    -The script mentions a free 4-Hour course with 32 videos that the creator has uploaded, as well as a Carrot Market clone coding course that is being updated to Next.js version 14.

  • What technologies are used in the Carrot Market clone coding course?

    -The Carrot Market clone coding course uses technologies like Tailwind, Prisma, PlanetScale, CloudFlare, and more. It also covers user authentication, file uploads, user profiles, reviews, CloudFlare Workers, and durable objects for serverless realtime experiences.

  • What is the recommended course for learning more about Next.js and taking advantage of its features?

    -The script recommends the Carrot Market clone coding course for learning more about Next.js and squeezing the framework from all its features.

  • What is the benefit of using the 'useClient' directive in Next.js 14?

    -The 'useClient' directive allows developers to specify components that need to use APIs of the user's browser, such as local storage or geolocation, or components that need to use event listeners for interactivity. It tells Next.js that the component should be hydrated in the user's browser.

  • What is the overall tone of the video script?

    -The overall tone of the video script is enthusiastic and excited about the new features and developer experience improvements in Next.js version 14.

Outlines

00:00

😊nextjs - The leading React framework

Paragraph 1 discusses nextjs, explaining that it is the number one React framework for building full-stack web applications. It lists some major websites built with nextjs and highlights key benefits of the latest version 14, specifically server components which improve performance by reducing code sent to the client, and server actions which simplify data mutations by eliminating the need for separate API endpoints.

05:02

😃Our full nextjs course updated for v14

Paragraph 2 mentions the speaker's free 4-hour nextjs course and paid full course on building a carot Market clone app, which covers advanced topics like authentication, file upload, user profiles etc. The course is being fully updated to leverage the capabilities of nextjs version 14 and existing buyers will get the new version for free.

Mindmap

Keywords

💡Next.js

Next.js is a popular React framework for building full-stack web applications. It is mentioned as the number one React framework in the video. Next.js allows server-side rendering and generating static websites for better performance. Popular websites like TikTok, Twitch and Hulu use Next.js.

💡Server Components

Server Components allow selectively rendering components on the server. This avoids sending component code to the browser. The video explains how Server Components improve performance and security by preventing access to database and API keys on the client side.

💡Server Actions

Server Actions allow executing functions securely on the server. The video gives the example of creating a user account without needing an API endpoint. Next.js handles passing data between component and server action.

💡Code Reduction

The video emphasizes how Next.js 14 features like Server Components and Server Actions reduce the amount of code needed. Examples are removing fetch calls to APIs and simplifying component code.

💡Developer Experience

Next.js 14 improves developer experience with Server Components and Actions. Coding is simplified with less repetition. The video highlights the productivity benefits.

💡Rendering

Rendering refers to generating the UI from React components. The video contrasts client-side and server-side rendering. Next.js does server-side rendering first for better performance.

💡Hydration

Hydration means rendering React components on client after server-side rendering. This makes the UI interactive. The video explains how Server Components avoid client hydration.

💡Suspense

Suspense allows components to wait for something before rendering. The video gives the example of showing a loading state with Suspense while fetching data for a post component.

💡Cloudflare Workers

Cloudflare Workers provide serverless computing. The video mentions using Workers and Durable Objects to build realtime experiences.

💡Live Shopping

Live shopping means realtime ecommerce streaming. The video references using Cloudflare Stream for live shopping in their example application.

Highlights

The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.

Transcripts

play00:00

nextjs is the number one react framework

play00:02

for building fullstack web applications

play00:04

the websites of Tik Tok twitch Hulu

play00:07

notion HBO Max chat GPT and many other

play00:11

big names are built with nextjs the

play00:13

latest version of nextjs the version 14

play00:16

landed with support for two features

play00:17

that I have been waiting for for a long

play00:19

long time server components and server

play00:22

actions server components was already a

play00:24

thing in version 13 but server actions

play00:26

are finally stabled since version 14 was

play00:28

released I have been upgrading raing all

play00:30

my projects to it and all I can say is

play00:33

wow the developer experience and

play00:34

productivity are through the roof I have

play00:37

deleted lots of lines of code there are

play00:39

libraries I don't even need anymore and

play00:41

my users download way less JS code

play00:44

server components allow us to choose if

play00:46

a component should be rendered only in

play00:48

the server or Not by default all

play00:50

versions of nextjs render your

play00:52

components twice once in the back end

play00:54

and once in the front end it pre-

play00:55

renders them in the back end so when a

play00:57

user goes to your page they will at

play00:59

least see a non-interactive version of

play01:01

your app and then it initializes a react

play01:03

app on top of the non-interactive UI to

play01:06

make it interactive this means the

play01:08

browser downloads the code of all the

play01:10

components to render them again in the

play01:12

browser because the browser downloads

play01:14

the code of the components that means

play01:15

that anybody could see their source code

play01:17

which means we can't connect to our

play01:19

database from them or expose our secret

play01:21

API Keys instead we need to fetch from

play01:24

an API that will securely talk to our

play01:25

database or use the API case in a

play01:28

backend or we can use ser components

play01:30

because they allow us to opt out of the

play01:32

second render that means the component

play01:34

will only be rendered once in the backet

play01:36

and only the resulting UI will be given

play01:38

to the user and not the component

play01:41

JavaScript code that has huge

play01:43

consequences for us that means the user

play01:45

doesn't have to download and render all

play01:47

the components of your application in

play01:48

the browser and it allows us to delete

play01:50

Crazy amounts of code we can go from

play01:52

this where we have to use a state use

play01:55

effect and call an API to this where we

play01:57

don't need to fetch an API we don't even

play02:00

need to have an API and we can just talk

play02:02

to the database directly the code for

play02:04

the component will never be downloaded

play02:06

by the user only the UI the component

play02:09

returns to handle loading states with

play02:11

server components we can use suspense

play02:13

when the user goes to the page they will

play02:14

immediately see a UI with a loading post

play02:17

text then when the post component is

play02:19

done fetching the post using streaming

play02:21

nextjs will replace the loading post

play02:24

text with the resulting UI of the post

play02:27

component just like that the need for an

play02:29

API and a library is gone Amazing all

play02:31

components are by default server

play02:33

components which means they will be

play02:34

rendered only one time if you need to

play02:36

use apis of the browser of the user like

play02:38

local storage or geolocation or if you

play02:41

need to use onclick or any other event

play02:43

listener for interactivity all you have

play02:45

to do is write used client at the top of

play02:47

the component like this that will tell

play02:49

nextjs that you want this component to

play02:51

be hydrated in the browser of the user

play02:53

used client does not mean the component

play02:55

will be rendered only in the client it

play02:56

means it will be rendered also in the

play02:58

client I think you use client is

play03:00

confusing because it sounds like the

play03:01

component would only be rendered in the

play03:03

client which isn't true is rendered in

play03:05

both server and client you can think of

play03:07

use client as use hydrate which is more

play03:10

accurate and easy to understand server

play03:11

actions is better seen than explained

play03:13

all you have to know is that they make

play03:15

the developer experience of data

play03:16

mutations incredible an example of a

play03:18

data mutation is when a user creates an

play03:20

account on your website for example

play03:21

without server actions we would have to

play03:23

have an unsubmit function in our

play03:25

component that will send a post request

play03:27

to an API route in API user to create an

play03:30

account for the user that submitted the

play03:31

form that means we also have to have an

play03:33

API endpoint in our backend that talks

play03:35

to the database and creates the user

play03:37

account or we can use server actions and

play03:39

get rid of the API completely as well as

play03:41

the fetch code that sends the data to

play03:43

the API to make our component look like

play03:45

this just like that the create user

play03:47

function is now going to run securely in

play03:50

the server nextjs will pass the form

play03:52

data that the user wrote in the front

play03:54

end to the function automatically to

play03:56

know what the state of the mutation is

play03:58

so we can show the the user a loading

play04:00

message or show the user some errors we

play04:02

have two hooks we can use one is the use

play04:05

form status hook that we can call from

play04:07

any child of the form like this and

play04:09

another one is the use form state that

play04:11

allows us to have more structure in our

play04:13

responses in case there is an error

play04:16

actions also have lots of cool functions

play04:18

to revalidate data check cookies or even

play04:20

redirect the user when the mutation is

play04:23

finished how cool is this again we can

play04:25

get rid of the API endpoint and fetch

play04:27

code completely and just write the logic

play04:29

right there in our component nextjs will

play04:32

handle it all it will pass data between

play04:34

component and action all behind the

play04:36

scenes and securely we don't have to do

play04:37

anything it just works that's it for

play04:39

this video if you want to learn more

play04:40

about nexs for free check out the free

play04:43

4-Hour course that I just finished

play04:44

uploading and that you can join right

play04:46

now for the low price of free 32 videos

play04:49

4 hours all free and if you want to

play04:51

learn even more about the next JS and

play04:54

squeeze the framework from all its

play04:55

features check out our carot Market

play04:58

clone coding course this this is a

play05:00

course that I recorded with nextjs

play05:01

version 12 and that I am now updating to

play05:04

version 14 I am re-recording it

play05:06

completely all 100% new everyone that

play05:09

bought the version 12 course will get

play05:12

the version 14 course for absolutely

play05:14

free no exceptions in Carro Market we

play05:16

build a fully fledged nextjs application

play05:19

with Tailwind Prisma Planet scale Cloud

play05:22

flare and more we Implement user

play05:24

authentication file uploads user

play05:26

profiles reviews and more we also learn

play05:28

about cloud their workers and learn

play05:30

about a durable object to build

play05:32

serverless realtime experiences and use

play05:35

cloud stream for live shopping as well

play05:37

it is absolutely awesome and this

play05:39

version is even better with the power of

play05:40

next js14 server components server

play05:43

actions and more I hope you found this

play05:44

video useful if you did please like it

play05:46

share it with your friends and subscribe

play05:48

to the channel thank you for watching as

play05:49

always on Kam see you on the next one

play05:58

byebye