NEW React 19 Changes Are Amazing!

Web Dev Simplified
27 Feb 202408:42

Summary

TLDRこのビデオでは、Reactのバージョン19で追加される主な7つの機能について説明しています。コンパイラの追加、アクションとフックの利用、クライアントとサーバーの区別、ドキュメントメタデータ、サスペンスの改善、ウェブコンポーネントのサポート改善、useフックの追加などが含まれます。ビデオの内容を正確に要約することで、視聴者の関心を引きつけています。

Takeaways

  • 😀 React 19 adds a compiler for improved performance and simpler code
  • 👍 Actions provide an easier way to handle forms and submissions
  • 🔥 useServer and useClient directives enable distinguishing between client/server code
  • 📑 Document metadata can be added directly in components
  • ⚙️ Suspense waits for styles, scripts etc to load before rendering page
  • 🔌 Web components will work much better in React 19
  • 😎 Forward refs are no longer needed thanks to automatic ref passing
  • 🎣 The new use hook replaces react.lazy for code splitting
  • 📚 A free course covers all the new React hooks
  • 🙌 Fewer hooks needed thanks to the new compiler

Q & A

  • What is the biggest change coming in React 19?

    -The biggest change is that React is adding a compiler, which will automatically take care of memorization that previously required hooks like useMemo and useCallback.

  • How will the new React compiler make applications faster?

    -The compiler will automatically find more instances where memorization should be used compared to what developers would manually add, resulting in faster applications.

  • What is the benefit of using actions instead of onSubmit in forms?

    -Actions provide built-in ways to handle form submission, error states, loading, and data that previously required custom code in onSubmit handlers.

  • How can the useOptimistic hook improve UX when submitting data?

    -useOptimistic allows showing optimistic updates to the UI, like liking a post, before getting a response from the server to improve perceived performance.

  • How does the new document metadata feature work?

    -You can put title, meta, and link tags anywhere in a component and React will automatically move them to the correct head location.

  • What Suspense improvements are coming in React 19?

    -Suspense will now wait for styles, scripts, and links to finish loading before rendering a page to prevent layout shifting.

  • Will web components work better in React 19?

    -Yes, React 19 will have improved web component capabilities and make them easier to implement.

  • Will Forward Ref still be required in React 19?

    -No, the ref prop will automatically be passed to all components, eliminating the need for Forward Ref.

  • What does the new use hook allow?

    -The use hook enables asynchronous loading of code and data along with running logic like context providers.

  • Where can I learn more about the new React hooks?

    -The author offers a free course that covers all React hooks, including the newest ones in React 19.

Outlines

00:00

🤓 React Compiler and Performance Improvements

React 19 will introduce a built-in compiler which will automatically memoize components like useMemo and useCallback did previously. This eliminates the need to manually add memoization, makes code simpler, faster, and easier to read and write.

05:01

🌟 Actions for Forms, Optimistic Updates

React 19 will have first-class support for form submissions via "actions" instead of onSubmit. This is integrated with new hooks like useFormStatus and useFormState to handle forms and submissions. There is also a new useOptimistic hook for optimistic UI updates.

Mindmap

Keywords

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

Highlights

React is adding a compiler in version 19 for the first time, which will automatically memoize code to improve performance.

The React compiler means you won't need hooks like useMemo or useCallback anymore since memorization will be handled automatically.

"Actions" are becoming a stable API in React for handling forms and submissions with built-in features like error handling.

React hooks like useFormStatus and useFormState make it easy to manage form state with the new Actions API.

The useOptimistic hook allows components to optimistically update with temporary data while waiting for a response from the server.

The useClient and useServer directives for distinguishing client vs. server code are becoming stable APIs available outside of Next.js.

A new <Title> component and other metadata tags will automatically be placed correctly when server rendering components.

Suspense will now wait for styles, scripts, and links to finish loading before rendering a page.

Web components will work much better in React 19 with improved integration.

The forwardRef wrapper will no longer be needed - refs can be passed directly as props.

The new use hook allows asynchronous loading of code and data.

useMemo, useCallback - no longer needed, compiler handles it.

useFormStatus, useFormState - easy form management.

useOptimistic - temporary optimistic UI updates.

use hook - async loading code/data.

Transcripts

play00:00

staying up to dat with everything that's

play00:02

changing in react is incredibly

play00:03

difficult so in this video I'm going to

play00:04

go through the seven main things that

play00:06

you need to understand about react

play00:08

version 19 I'm going to make it as

play00:09

simple and quick as possible so you can

play00:11

get up to speed with everything you need

play00:12

to know before it even

play00:17

releases welcome back to webd simplified

play00:19

my name is Kyle and my job is to

play00:21

simplify the web for you so you can

play00:22

start building your dream project sooner

play00:24

as you can see there's a lot of

play00:25

documentation that react has released

play00:27

about what's going to be happening in

play00:28

version 19 I'm going to go through in

play00:30

order of importance everything that's

play00:31

changing and the biggest change is going

play00:33

to be that they're actually adding a

play00:35

compiler to react this is actually a

play00:37

really big deal because For the Longest

play00:39

Time react only ran in the browser and

play00:40

there's no compile Step at all and now

play00:42

other Frameworks have come along such as

play00:44

Astro and spelt and they added in their

play00:46

own compile step and this compile step

play00:48

just takes care of a lot of things for

play00:50

you behind the scenes so you don't have

play00:51

to write extra code for that but since

play00:53

react never had that we had different

play00:55

hooks like use memo use callback and the

play00:57

memo function that allowed you to do

play00:59

extra performance things to make sure

play01:00

your code ran performant since there was

play01:02

no compiler to do that for you

play01:04

automatically well with react version 19

play01:06

the big thing that they're pushing is

play01:07

this react compiler so that means that

play01:09

automatically react is going to add its

play01:11

own memorization for things like use

play01:13

memo use callback and the memo function

play01:15

so you never have to use those hooks or

play01:17

functions ever again it's just going to

play01:19

be automatically taken care of for you

play01:21

by the compiler so anytime you would

play01:22

normally need to use memo or use call

play01:24

back you can just completely remove that

play01:26

and the compiler will take care of it

play01:27

for you now this is a huge win because

play01:29

not not only does it make your code

play01:31

simpler and easier to read and write

play01:32

since you no longer have to think about

play01:34

this but it also will make your code

play01:36

faster because it's almost always the

play01:37

case that the actual compiler is going

play01:39

to find more instances of where you

play01:41

should be doing memoization than where

play01:43

you would normally find it yourself so

play01:45

having this extra compile step is going

play01:47

to make your application faster and

play01:48

easier to write and is honestly the

play01:50

thing I'm most excited about for react

play01:51

version 19 because these hooks are the

play01:54

reason that react is so confusing and

play01:56

complicated to write especially as you

play01:57

get larger and larger applications where

play02:00

performance is really important now the

play02:02

next two main features I want to talk

play02:03

about are something that you may be

play02:04

familiar with if you've already worked

play02:06

inside of nextjs and that's the idea of

play02:08

actions as well as the used client and

play02:10

the used server directive we'll start by

play02:12

talking about actions since this affects

play02:14

you a little bit more directly but if

play02:16

you've ever worked inside a nextjs you

play02:17

know that you can create a form and

play02:19

instead of passing an on submit you pass

play02:20

it an action and this action will take

play02:22

in all of your different form data and

play02:24

you can do whatever you want with this

play02:25

action and if you're using nextjs this

play02:28

action can even run on the server in

play02:29

instead of running in the client well

play02:31

the big change with react 19 is first

play02:33

that they're making that this is a

play02:34

stable feature because right now it's

play02:36

not really a stable feature and secondly

play02:38

they're adding it so it actually works

play02:40

inside of client or server applications

play02:42

so this action that I pass in here which

play02:44

is just a function that takes in my form

play02:46

data can either run on the client or it

play02:48

can run on the server and it has other

play02:50

hooks built around it that make dealing

play02:52

with State and loading and so on

play02:54

incredibly easy as you can see here we

play02:55

have hooks called use form status and

play02:57

use form State and if you want to learn

play02:59

more about these new hooks I actually

play03:01

have an entirely free course on every

play03:03

single react hook you need to know and I

play03:05

constantly update this course whatever

play03:07

new hooks are released so if that sounds

play03:08

interesting check out the link down in

play03:10

the description below and sign up for

play03:11

that course and again I'll update it as

play03:13

soon as new hooks are released or

play03:14

changed but essentially this new way of

play03:16

using an action instead of an onsubmit

play03:18

just gives you a more built-in way in

play03:20

react to actually deal with forms form

play03:22

submissions form error states form

play03:24

loading form data everything that there

play03:26

is to do with forms can be done much

play03:28

easier by using this action instead of

play03:30

using an onsubmit Handler cuz a lot of

play03:32

that boiler plate like loading error

play03:33

messages and so on is automatically

play03:35

taken care of for you by these two hooks

play03:37

of use form status and use form State

play03:40

and now another additional hook that's

play03:41

being added is use optimistic again I

play03:43

entirely cover that hook inside of this

play03:45

course and this hook just allows you to

play03:47

do optimistic updates so for example if

play03:49

you click on the like button on like a

play03:51

tweet or a post what will happen is

play03:53

it'll automatically show you that that

play03:54

has been liked while the server is

play03:56

processing and then once the actual

play03:58

result comes back it'll either change it

play04:00

to liked or unliked based on if there's

play04:01

an error or not so an optimistic update

play04:03

just shows you the most optimistic thing

play04:05

like saying okay if you click on this

play04:07

like button you want to like it so it'll

play04:08

show is liked immediately even if it

play04:10

hasn't been submitted to the server yet

play04:12

so this is just a really simple hook

play04:13

that makes doing that much easier and

play04:15

it's honestly really cool and magical

play04:16

how this actually works and again I have

play04:18

a full video on that in the course and

play04:20

this hooks course that I have is also

play04:22

completely free by the way I'm not sure

play04:23

if I mentioned that so if you are

play04:24

interested in it's completely free all

play04:26

you have to do is sign up for the course

play04:27

nothing else now the next thing is

play04:29

talking about the actual client versus

play04:31

server directives so you know that you

play04:32

can put use client or use server at the

play04:34

top of a file inside of nextjs to

play04:36

determine if that code is running on the

play04:37

server or if that code is being pushed

play04:39

down and ran on the client so this is

play04:41

just a really easy way for you to

play04:43

distinguish between these two things and

play04:44

right now it's really only usable inside

play04:46

of nextjs but with this newest version

play04:48

of react 19 that's coming out this is

play04:50

going to be a stable release instead of

play04:52

something that is more of an

play04:53

experimental status which means other

play04:55

Frameworks can be built around these

play04:56

used client and used server features and

play04:58

we will hopefully see more Frameworks

play05:00

than just nextjs or remix actually have

play05:03

these used client and used server

play05:04

features and we can really start to play

play05:06

around with the power of this in more

play05:07

than just nextjs which I think is really

play05:09

cool and important because more and more

play05:11

Frameworks add to more Innovation which

play05:13

pushes all the Frameworks further now

play05:15

the next thing I want to talk about is

play05:16

this document metadata section and

play05:17

essentially what this allows you to do

play05:19

is to put a title tag a meta tag or a

play05:22

link tag that deals with metadata

play05:23

anywhere inside of your react component

play05:26

and it's automatically going to make

play05:27

sure it moves it to the right location

play05:28

inside of like the or wherever else it

play05:30

needs to go so if you want to have like

play05:32

a different title on multiple different

play05:33

pages you can just drop this title

play05:35

component anywhere in your component and

play05:37

it's just going to work out of the box

play05:38

which is really nice and they mostly did

play05:40

this so that you can have certain things

play05:42

work fine when you're doing server

play05:43

rendering and react server components

play05:45

they did this because certain things

play05:46

like react helmet and other libraries

play05:48

like that won't work super well with

play05:49

this new way of doing things in react so

play05:51

they just built in their own way of

play05:52

doing that which is just a nice quality

play05:54

of life feature the next thing I want to

play05:56

talk about has to do with suspense so

play05:58

you may not be familiar with suspense

play05:59

it's a new react 18 feature that allows

play06:01

you to essentially stream in things so

play06:03

you can stream your data in to be

play06:05

rendered it's really popular in

play06:06

something like nextjs and essentially

play06:09

what they're doing here is empowering

play06:10

suspense by making sure that it waits

play06:12

for certain things like your style tags

play06:13

links and scripts to load so if you have

play06:15

certain style tags that are only loaded

play06:17

on certain pages or certain components

play06:19

or you have script tags that are running

play06:20

on only certain pages this is going to

play06:22

make sure that all your Styles and all

play06:24

your script tags are actually downloaded

play06:26

and ran before the page actually shows

play06:28

that way you don't have an instance

play06:29

where your page renders but none of your

play06:31

CSS has been downloaded yet this is just

play06:33

essentially making sure all of that will

play06:34

work well together and it even gives you

play06:36

a simple API that you can use to do this

play06:38

with more than just style link and

play06:40

script tags if you really want to but

play06:41

that's a rather Advanced feature now

play06:43

those are the main features mentioned in

play06:45

this article but there's actually quite

play06:46

a few additional things that are coming

play06:47

along one thing is that web components

play06:49

are going to work much better in react

play06:51

19 they mention it very briefly inside

play06:53

this article it's like one sentence that

play06:55

they mention it but they do mention that

play06:57

web components are now going to be

play06:58

working much better with react 19 so if

play07:00

you want to use web components in react

play07:02

it should be much easier to implement

play07:04

them inside of a react project because

play07:05

in the past that was something that was

play07:07

really difficult which is why you would

play07:08

almost always see when you're working at

play07:10

libraries there would be a web component

play07:11

library and then like a react specific

play07:13

version because it was so hard to make

play07:15

web components work in react but now it

play07:16

should be much easier to get them to

play07:18

play well together now these last couple

play07:20

features are really small so I'll go

play07:21

through them quite quickly the first is

play07:22

that forward ref is something you are

play07:24

never going to need to use ever again

play07:26

and that's because the ref prop that you

play07:28

normally get by using forward ref is

play07:30

automatically going to be passed to

play07:31

every component inside of react so you

play07:33

can just use refs by just passing it

play07:35

along as a second prop and you don't

play07:36

need this crappy forward ref function

play07:38

wrapping stuff anymore after this next

play07:41

is that you actually won't really need

play07:42

to use react. La anymore and that's

play07:44

because a brand new hook called use just

play07:46

simply use is being added to react and

play07:49

this use hook allows you to do a lot of

play07:50

really cool stuff it allows you to

play07:52

essentially asynchronously load things

play07:54

whether that's going to be

play07:54

asynchronously loading JavaScript files

play07:57

whether it's going to be asynchronously

play07:58

running different proc promises or maybe

play08:00

you even want to run your context

play08:02

through here all of those things are

play08:03

possible with the use hook it's honestly

play08:05

a rather complex hook that breaks all of

play08:07

the rules of normal hooks so if you want

play08:08

to learn more about that hook I highly

play08:10

recommend checking out that free course

play08:12

I go in- depth into everything you can

play08:13

do with this hook because honestly it's

play08:15

one of the coolest hooks that was added

play08:16

to react but it can be incredibly

play08:18

complicated because like I said it

play08:19

breaks all of the rules of every other

play08:21

hook out there so if you're interested

play08:23

in checking out this use hook I highly

play08:24

recommend checking out that free course

play08:26

and that's all the big new changes

play08:28

coming to react 19 if you want to make

play08:30

sure you stay up to date with all the

play08:31

new hooks that are coming out in react

play08:32

again I highly recommend you check out

play08:34

that free course because as soon as new

play08:35

hooks are added or changed I constantly

play08:37

update that course with that said thank

play08:39

you very much for watching and have a

play08:40

good day