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

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

Summary

TLDRNext.jsは、フルスタックWebアプリケーションを構築するためのNo.1のReactフレームワークです。TikTok、Twitch、Hulu、Notion、HBO Max、Chat GPTなど、多くの大手企業のウェブサイトがNext.jsで構築されています。最新バージョンのNext.js 14では、長く待望されていたサーバーコンポーネントとサーバーアクションの2つの機能がサポートされました。アップグレードすることで、開発者の経験と生産性が大幅に向上し、コードの量が劇的に削減されました。また、ユーザーはより少ないJavaScriptコードをダウンロードする必要があります。サーバーコンポーネントを使用すると、コンポーネントをサーバーでのみレンダリングするか、それともしないかを選択できます。これにより、データベースへの接続や秘密のAPIキーの露出を防ぐことができます。また、サーバーアクションを使用することで、データの変更に関する開発者の経験を大幅に向上させることができます。たとえば、ユーザーがウェブサイトでアカウントを作成する場合、サーバーアクションを使用してAPIやfetchコードを完全に排除し、コンポーネント内でロジックを直接記述できます。Next.jsは、コンポーネントとアクション間のデータを安全に処理し、シームレスに動作します。さらに、無料の4時間コースやCarro Marketクローンのコーディングコースで、Next.jsの機能をさらに学ぶことができます。

Takeaways

  • 🚀 Next.jsは、TikTokやTwitch、Hulu、Notion、HBO Max、Chat GPTなど、多くの有名なウェブサイトで使用されているReactフレームワークです。
  • 🎉 Next.jsのバージョン14では、サーバーコンポーネントとサーバーアクションの2つの新機能が追加され、開発者の体験と生産性が大幅に向上しました。
  • 🛠️ サーバーコンポーネントを使用すると、コンポーネントをサーバー上でのみレンダリングするか、またはクライアントでもレンダリングするかを選択できます。
  • 🔒 サーバーコンポーネントは、コンポーネントのJavaScriptコードをユーザーにダウンロードさせないため、データベースへの接続やシークレットAPIキーの露出を防ぐことができます。
  • ⚙️ サーバーアクションを使用すると、データの変更(ユーザーアカウントの作成など)を安全に行うことができます。これにより、APIエンドポイントやfetchコードを完全に排除できます。
  • 📦 バージョン14以降、すべてのコンポーネントはデフォルトでサーバーコンポーネントになり、必要に応じて`use client`を使用してブラウザでハイドレートさせることができます。
  • 🔄 `use client`は、コンポーネントがクライアントでのみレンダリングされることを意味するのではなく、サーバーとクライアントの両方でレンダリングされることを示します。
  • 📚 Next.jsのバージョン14では、ReactのuseStateやuseEffectを使用する代わりに、データベースに直接アクセスできるため、コードの削減が可能です。
  • 🌐 Suspenseを使用すると、サーバーコンポーネントでローディング状態を扱えるため、APIやライブラリの必要性がなくなります。
  • 📈 フォームのステータスを子コンポーネントから取得できる`useFormStatus`フックと、より構造化されたレスポンスを持つ`useFormState`フックが利用できます。
  • 🛒 無料のNext.jsコースやCarro Marketクローンのコーディングコースで、ユーザー認証、ファイルアップロード、ユーザープロフィール、レビューなどを含む完全なNext.jsアプリケーションを学ぶことができます。
  • 🎓 Carro Marketコースは、バージョン12からバージョン14に更新され、購入者は無料で新しいバージョンを受け取ります。

Q & A

  • Next.js はどのようなフレームワークですか?

    -Next.js は、フルスタックWebアプリケーションを構築するためのReactフレームワークで、TikTok、Twitch、Hulu、Notion、HBO Max、Chat GPTなどの有名なウェブサイトがNext.jsで構築されています。

  • Next.jsのバージョン14ではどのような新機能が導入されましたか?

    -Next.jsのバージョン14では、サーバーコンポーネントとサーバーアクションという2つの新機能が導入されました。サーバーコンポーネントはバージョン13で既に存在していましたが、サーバーアクションはバージョン14でようやく安定版となりました。

  • サーバーコンポーネントとは何ですか?

    -サーバーコンポーネントは、コンポーネントがサーバー上でのみレンダリングされるかどうかを選択できる機能です。デフォルトでは、Next.jsのすべてのバージョンでコンポーネントは2回レンダリングされますが、サーバーコンポーネントを使うことで、ブラウザでの第2回のレンダリングを省略できます。

  • サーバーアクションとは何ですか?

    -サーバーアクションは、データのミューテーションを処理するための機能で、ユーザーがアカウントを作成するなど、データベースに直接アクセスできるようにします。これにより、APIやfetchコードを使わずに、サーバー上で安全に処理を実行できます。

  • Next.jsのサーバーコンポーネントを使用する利点は何ですか?

    -サーバーコンポーネントを使用することで、ユーザーがブラウザですべてのコンポーネントをダウンロードしてレンダリングする必要がなくなり、コードの量を大幅に削減できます。また、ブラウザのAPIやユーザーのブラウザイベントを必要とする場合は、`used client`と記載することでブラウザでハイドレーションさせることができます。

  • Next.jsのバージョン14では、どのようにしてローディング状態を扱うことができますか?

    -Next.jsのバージョン14では、Suspenseを使用してローディング状態を扱うことができます。ユーザーがページに行くと、まずローディングテキストが表示され、コンポーネントがデータをフェッチすると、ローディングテキストが結果のUIに置き換えられます。

  • サーバーアクションを使用する際の利点は何ですか?

    -サーバーアクションを使用することで、APIエンドポイントやfetchコードを完全に排除し、コンポーネント内でロジックを直接記述できます。また、Next.jsはデータの受け渡しやエラーメッセージの表示など、バックグラウンドで安全に処理を行います。

  • Next.jsのフォームステータスフックとは何ですか?

    -フォームステータスフックは、フォームの子のコンポーネントから呼び出すことができるフックで、ミューテーションの状態を知ることができます。これにより、ユーザーにローディングメッセージやエラーを表示することができます。

  • Next.jsのフォームステートフックとは何ですか?

    -フォームステートフックは、より構造化されたレスポンスを提供し、エラーが発生した場合には詳細な情報を得ることができます。これにより、フォームのステートをより柔軟に扱うことができます。

  • Next.jsのバージョン14で提供されるCarro Marketクローンのコーディングコースでは何を学ぶことができますか?

    -Carro Marketクローンのコーディングコースでは、ユーザー認証、ファイルアップロード、ユーザープロフィール、レビューなどを含む完全なNext.jsアプリケーションを構築し、クラウドワーカー、Durable Objectを使ったサーバーレスリアルタイムエクスペリエンスの構築方法を学ぶことができます。また、Cloudflareと連携してライブショッピングを実現する方法も学びます。

  • Next.jsのバージョン12のコースを購入していた場合、バージョン14のコースはどのようにして入手できますか?

    -バージョン12のコースを購入していた人は、誰もが自動的にバージョン14のコースを無料で入手できます。これは完全に新しいレコーディングで、バージョン14のNext.jsのパワーを活用しています。

Outlines

00:00

🚀 Next.js 14の新機能: Server ComponentsとServer Actionsの紹介

Next.jsはReactフレームワークの中でもトップクラスで、TikTokやTwitch、Hulu、Notion、HBO Max、Chat GPTなど、多くの有名なウェブサイトが構築されています。最新のバージョン14では、Server ComponentsとServer Actionsという2つの注目の新機能が追加されました。Server Componentsは既にバージョン13で存在していたものの、バージョン14ではServer Actionsが安定版となりました。これにより、開発者の経験と生産性が大幅に向上し、コード量が削減されました。また、Server Componentsを使用することで、コンポーネントをサーバー側でのみレンダリングし、ユーザーにはJavaScriptコードがダウンロードされなくなります。さらに、Server Actionsを使えば、データの変更を安全に行うことができます。これにより、APIのエンドポイントやfetchコードを排除し、コンポーネント内でロジックを直接記述することが可能となります。

05:02

📚 Next.jsの学習コース紹介とCarro Marketの構築

Next.jsについてさらに学びたい方は、無料で提供されている4時間のコースに参加できます。また、Next.jsを活用したCarro Marketの構築コースも用意されており、バージョン12でレコーディングされたコンテンツがバージョン14にアップデートされています。このコースでは、Tailwind、Prisma、PlanetScale、Cloudflareなどを用いて、ユーザー認証、ファイルアップロード、ユーザープロフィール、レビューなどを含む完全なNext.jsアプリケーションを構築します。さらに、CloudflareのWorkersとDurable Objectsを使ったサーバーレスのリアルタイム体験の構築方法も学ぶことができます。

Mindmap

Keywords

💡Next.js

Next.jsは、Reactフレームワークで、フルスタックウェブアプリケーションを構築するための人気があります。このフレームワークは、TikTokやTwitch、Hulu、Notion、HBO Maxなどの有名なウェブサイトで使用されています。このキーワードは、ビデオの中心テーマであり、Next.jsのバージョン14の新機能について説明しています。

💡Server Components

サーバーコンポーネントは、Next.jsのバージョン13から存在していたが、バージョン14では機能が強化されました。これにより、コンポーネントをサーバー上でのみレンダリングするか、あるいはクライアントにもレンダリングするかを選択できます。これは、ユーザーがブラウザ上ですべてのコンポーネントを再レンダリングする必要がなく、コードの量を大幅に削減できることを意味しています。

💡Server Actions

サーバーアクションは、バージョン14で安定化された新機能で、データの変更(例えばユーザーアカウントの作成)を安全に行うことができます。これにより、APIエンドポイントやfetchコードを完全に排除し、コンポーネント内でロジックを直接記述することが可能になります。

💡Suspense

サスペンスは、Next.jsのサーバーコンポーネントと組み合わせて使用することで、非同期データの取得中にローディング状態を表示することができます。ビデオでは、ポストコンポーネントがデータを取得するまでローディングテキストが表示され、取得が完了するとUIが置き換えられる様子が説明されています。

💡use client

use clientは、Next.jsで使用されるディレクティブで、コンポーネントをブラウザでハイドレートする必要があることを示します。これは、ローカルストレージやジオロケーションなどのブラウザAPIを使用する場合や、onclickなどのイベントリスナーが必要な場合に使用されます。

💡Data Mutations

データの変更は、ユーザーがウェブサイト上でアカウントを作成するなど、データベースに記録を追加または変更する操作のことを指します。ビデオでは、サーバーアクションを使用することで、これらの変更を安全にサーバー上で行う方法が説明されています。

💡useFormStatus

useFormStatusフックは、フォームの子のコンポーネントから呼び出して、フォームのステータスを取得することができます。これは、ユーザーにローディングメッセージやエラーを表示するために使用されます。

💡useFormState

useFormStateフックは、より構造化されたレスポンスを可能にするために使用されます。エラーが発生した場合など、より詳細な情報を必要とする場面で役立ちます。

💡Carrot Market Clone

Carrot Market Cloneは、ビデオで紹介されているNext.jsアプリケーションの構築コースで構築される、完全なNext.jsアプリケーションです。ユーザー認証、ファイルアップロード、ユーザープロフィール、レビューなどを含む機能を実装しています。また、クラウドワーカーや持続的オブジェクトを使用して、サーバーレスのリアルタイム体験を構築する方法も学ぶことができます。

💡Tailwind

Tailwindは、Carrot Market Cloneで使用されるCSSフレームワークで、迅速なUI開発を可能にします。ビデオでは、Next.jsと組み合わせて使用され、効率的なウェブアプリケーションの開発を助ける役割を果たしています。

💡Vercel

Vercelは、Next.jsアプリケーションをホストするためのプラットフォームで、ビデオではアプリケーションのデプロイや配信に使用されています。Next.jsはVercelによって作成され、双方がシームレスに連携することで、開発者体験を向上させています。

Highlights

Next.js is the leading React framework for full-stack web applications.

Popular websites like TikTok, Twitch, Hulu, Notion, HBO Max, and Chat GPT are built with Next.js.

Next.js version 14 introduces server components and server actions, two highly anticipated features.

Server components allow for rendering components on the server by default, enhancing security and performance.

Server actions streamline data mutations, eliminating the need for traditional APIs and fetch code.

Developer experience and productivity have significantly improved with the upgrade to version 14.

The new version enables the deletion of redundant code and the removal of unnecessary libraries.

Users now download less JavaScript code thanks to the optimizations in Next.js version 14.

Suspense can be used with server components to handle loading states effectively.

The 'use client' directive indicates components that require browser APIs or interactivity.

Server actions provide a secure way to perform data mutations directly on the server.

Hooks like 'use form status' and 'use form state' offer structured responses and revalidation for forms.

The Next.js framework now supports building serverless, real-time experiences with its server components and actions.

A free 4-hour course on Next.js is available for those wanting to learn more about the framework.

An updated course on building a full-fledged Next.js application is being offered, including version 14 updates.

The Carro Market clone coding course covers advanced Next.js features like user authentication and file uploads.

Next.js version 14 is praised for its ability to simplify and secure the development process.

The video concludes by encouraging viewers to like, share, and subscribe for more content on Next.js.

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

Rate This

5.0 / 5 (0 votes)

Étiquettes Connexes
Next.jsサーバーコンポーネントサーバーアクションデータ取得コード削減API不要化Reactフレームワークウェブアプリケーション開発体験向上フルスタックデータミューテーションユーザー認証ファイルアップロード
Besoin d'un résumé en anglais ?