WEBVTT

00:00:00.000 --> 00:00:03.220
The React team shared an update with

00:00:03.220 --> 00:00:06.540
us, which is pretty exciting for a couple

00:00:06.540 --> 00:00:07.120
of reasons.

00:00:07.560 --> 00:00:10.400
The first reason is that it's been some

00:00:10.400 --> 00:00:14.320
time since we received at least an official

00:00:14.320 --> 00:00:17.820
update, I guess, if you define official as

00:00:17.820 --> 00:00:19.300
the React blog.

00:00:19.900 --> 00:00:22.040
That's of course not entirely true,

00:00:22.180 --> 00:00:24.460
because the React team does also

00:00:24.460 --> 00:00:26.540
communicate on other channels, for

00:00:26.540 --> 00:00:30.220
example on X, but of course also

00:00:30.220 --> 00:00:33.580
because a lot of React development

00:00:33.580 --> 00:00:37.220
recently happened in the context of

00:00:37.220 --> 00:00:41.200
Next.js or at least was communicated in

00:00:41.200 --> 00:00:44.320
the context of Next.js, but I'll get back to

00:00:44.320 --> 00:00:44.540
that.

00:00:44.840 --> 00:00:47.040
So it's pretty exciting because the last

00:00:47.040 --> 00:00:50.160
official blog post we got on the React

00:00:50.160 --> 00:00:55.620
blog was on May the 3rd, 2023, so almost

00:00:55.620 --> 00:00:59.320
a year ago, and now on February 15th,

00:00:59.340 --> 00:01:02.420
2024, we got another blog post, another

00:01:02.420 --> 00:01:04.420
update and a pretty exciting one,

00:01:04.599 --> 00:01:07.940
because in this update we learn a lot

00:01:07.940 --> 00:01:11.420
about the relatively near future of React,

00:01:11.700 --> 00:01:14.880
about React version 19, which will be the

00:01:14.880 --> 00:01:18.380
next major version of React, and about

00:01:18.380 --> 00:01:20.700
some exciting features that will be

00:01:20.700 --> 00:01:22.120
included in that version.

00:01:22.520 --> 00:01:25.500
In addition, there is the announcement, I

00:01:25.500 --> 00:01:28.460
guess, of React Conf 2024, which is

00:01:28.460 --> 00:01:32.080
scheduled for May 15th and 16th this

00:01:32.080 --> 00:01:34.220
year, but of course that's not the main

00:01:34.220 --> 00:01:35.340
thing of that blog post.

00:01:35.440 --> 00:01:37.960
Instead, in that blog post, where we

00:01:37.960 --> 00:01:40.260
learn more about React's near future,

00:01:40.860 --> 00:01:44.840
the main topic probably is the new

00:01:44.840 --> 00:01:48.140
React compiler on which the React team

00:01:48.140 --> 00:01:49.880
has been working for a while now.

00:01:50.580 --> 00:01:53.200
Now, this React compiler is called

00:01:53.200 --> 00:01:56.280
react-forget, and the idea behind this

00:01:56.280 --> 00:02:00.700
compiler is that it will take a look at your

00:02:00.700 --> 00:02:04.720
React code, essentially, and it will try to

00:02:04.720 --> 00:02:07.360
do memoization for you.

00:02:07.680 --> 00:02:08.960
Now, what does this mean?

00:02:09.539 --> 00:02:13.100
Well, in React, as of today, without that

00:02:13.100 --> 00:02:16.020
compiler, you sometimes have to use

00:02:16.020 --> 00:02:19.140
the useMemo hook or the useCallback

00:02:19.140 --> 00:02:23.240
hook or the memo function to wrap

00:02:23.240 --> 00:02:26.600
logic or components to make sure that

00:02:26.600 --> 00:02:29.420
they don't re-render unnecessarily,

00:02:29.820 --> 00:02:33.040
because the way React works, it can

00:02:33.040 --> 00:02:35.480
actually render components and

00:02:35.480 --> 00:02:38.580
re-evaluate components unnecessarily

00:02:38.580 --> 00:02:42.260
because it doesn't always understand if

00:02:42.260 --> 00:02:46.140
a re-evaluation cycle is necessary or not,

00:02:46.560 --> 00:02:48.460
and you therefore have to use these

00:02:48.460 --> 00:02:51.480
hooks and so on to tell it that some value

00:02:51.480 --> 00:02:53.880
didn't change in a certain component

00:02:53.880 --> 00:02:57.140
and therefore no re-evaluation of that

00:02:57.140 --> 00:02:59.560
component is needed, things like that.

00:03:00.040 --> 00:03:02.820
Now, of course, we have all these tools in

00:03:02.820 --> 00:03:05.220
React, though, so why do we need a

00:03:05.220 --> 00:03:07.620
compiler and what is it really about,

00:03:07.680 --> 00:03:08.700
what is memoization?

00:03:09.460 --> 00:03:11.560
Well, we have to use these different

00:03:11.560 --> 00:03:13.960
tools, useMemo, useCallback, and so on,

00:03:14.100 --> 00:03:17.520
to tell React when to not render or

00:03:17.520 --> 00:03:21.360
re-evaluate a component, and this

00:03:21.360 --> 00:03:25.020
compiler, react-forget, is about doing

00:03:25.020 --> 00:03:28.220
that for us so that we don't need to use

00:03:28.220 --> 00:03:31.300
useMemo or useCallback or the memo

00:03:31.300 --> 00:03:34.960
function anymore, but that instead, with

00:03:34.960 --> 00:03:38.400
help of that compiler, React is able to

00:03:38.400 --> 00:03:41.240
know and find out whether a

00:03:41.240 --> 00:03:43.300
component really should be

00:03:43.300 --> 00:03:47.040
re-evaluated or not, so that React gains a

00:03:47.040 --> 00:03:49.580
deeper understanding of your code, you

00:03:49.580 --> 00:03:52.120
could say, and therefore, with that

00:03:52.120 --> 00:03:55.540
compiler, as a React developer, you

00:03:55.540 --> 00:03:58.540
would have to worry less or maybe not

00:03:58.540 --> 00:04:01.700
at all about making sure that

00:04:01.700 --> 00:04:04.640
unnecessary re-evaluations are

00:04:04.640 --> 00:04:05.200
prevented.

00:04:05.820 --> 00:04:08.300
The React compiler would do that for

00:04:08.300 --> 00:04:09.740
you in that future.

00:04:10.220 --> 00:04:12.660
And that future is not too distant

00:04:12.660 --> 00:04:15.760
because in that blog post, which the

00:04:15.600 --> 00:04:18.480
React team shared, they also mentioned

00:04:18.480 --> 00:04:21.180
that this React compiler is no longer a

00:04:21.180 --> 00:04:23.600
research project, but that it instead

00:04:23.600 --> 00:04:26.440
already powers Instagram.com in

00:04:26.440 --> 00:04:29.860
production, so this compiler is already

00:04:29.860 --> 00:04:33.220
being used on a large-scale project and

00:04:33.220 --> 00:04:36.060
it seems to work quite well, otherwise

00:04:36.060 --> 00:04:38.940
they wouldn't be announcing it here for

00:04:38.940 --> 00:04:42.040
all React developers in the near future.

00:04:42.680 --> 00:04:44.620
Now, it's also worth noting and

00:04:44.640 --> 00:04:48.340
mentioned in this official blog post that

00:04:48.340 --> 00:04:50.820
this compiler and the existence of that

00:04:50.820 --> 00:04:53.820
compiler will not change the general

00:04:53.820 --> 00:04:57.800
React mental model, where the UI is

00:04:57.800 --> 00:05:02.020
essentially a function of your data and

00:05:02.020 --> 00:05:02.720
your state.

00:05:02.860 --> 00:05:06.880
That will not change, it's just meant to

00:05:06.880 --> 00:05:11.080
decrease the complexity of the code you

00:05:11.080 --> 00:05:13.920
have to write, or at least get rid of that

00:05:13.920 --> 00:05:16.500
extra work you had to do regarding

00:05:16.500 --> 00:05:19.060
those unnecessary render cycles that

00:05:19.060 --> 00:05:20.180
needed to be prevented.

00:05:20.620 --> 00:05:22.640
Which of course also was not just

00:05:22.640 --> 00:05:25.340
annoying, but also a potential source for

00:05:25.340 --> 00:05:28.300
bugs and problems, so it's great if we

00:05:28.300 --> 00:05:29.300
get some help there.

00:05:29.680 --> 00:05:31.900
Now, they also mentioned in that blog

00:05:31.900 --> 00:05:35.320
post that in order for this compiler to

00:05:35.320 --> 00:05:39.040
really work well, you must make sure

00:05:39.040 --> 00:05:43.140
that the React code you write follows

00:05:43.140 --> 00:05:46.560
certain rules or best practices, and

00:05:46.560 --> 00:05:48.700
therefore the React team recommends

00:05:48.700 --> 00:05:52.520
that if you want to make sure that you

00:05:52.520 --> 00:05:55.720
follow React's rules, you enable strict

00:05:55.720 --> 00:05:58.940
mode in your React projects and that

00:05:58.940 --> 00:06:03.420
you use React's ESLint plugin, so that

00:06:03.420 --> 00:06:06.880
you get early warnings if somewhere in

00:06:06.880 --> 00:06:09.880
your code you have code that technically

00:06:09.880 --> 00:06:13.540
works, but is not optimal, because that

00:06:13.540 --> 00:06:16.000
code then might not be handled by the

00:06:16.000 --> 00:06:18.060
compiler in the best possible way.

00:06:18.480 --> 00:06:21.360
Though it's also worth mentioning that

00:06:21.360 --> 00:06:24.960
the compiler, as it sounds from that blog

00:06:24.880 --> 00:06:29.080
post at least, will work such that it

00:06:29.080 --> 00:06:32.820
doesn't crash if somewhere in your code

00:06:32.820 --> 00:06:35.600
you have code that can't be analyzed

00:06:35.600 --> 00:06:39.400
and optimized automatically, it just

00:06:39.400 --> 00:06:41.820
won't be able to do anything with that

00:06:41.820 --> 00:06:42.620
code instead.

00:06:43.040 --> 00:06:45.280
So it will skip compilation if it

00:06:45.280 --> 00:06:47.440
determines that it isn't safe to compile

00:06:47.440 --> 00:06:48.020
your code.

00:06:48.400 --> 00:06:50.920
So that's that React compiler and it's a

00:06:50.920 --> 00:06:54.180
really exciting initiative and project and I

00:06:54.180 --> 00:06:57.100
can't wait to start using it and hopefully

00:06:57.100 --> 00:06:59.800
get rid of a bunch of boilerplate code in

00:06:59.800 --> 00:07:00.520
my codebase.

00:07:00.960 --> 00:07:03.520
Now that compiler isn't everything that's

00:07:03.520 --> 00:07:04.440
announced here though.

00:07:04.680 --> 00:07:06.900
In addition we also get more details

00:07:06.900 --> 00:07:11.460
about actions or server actions as most

00:07:11.460 --> 00:07:13.340
developers might know them.

00:07:13.780 --> 00:07:16.300
Though the blog post explicitly

00:07:16.300 --> 00:07:19.720
mentions that what was previously

00:07:19.720 --> 00:07:24.020
meant to be server actions, so a feature

00:07:24.020 --> 00:07:27.420
that allows you to run code on the server

00:07:27.420 --> 00:07:30.480
after a form is submitted, now actually

00:07:30.480 --> 00:07:33.940
became actions that can be used either

00:07:33.940 --> 00:07:37.160
on the server or also on the client, so

00:07:37.160 --> 00:07:39.640
that this actions feature, which is about

00:07:39.640 --> 00:07:42.520
to be added to React, will actually

00:07:42.520 --> 00:07:46.020
simplify the process of handling form

00:07:46.020 --> 00:07:48.700
submissions in React, even if it's just a

00:07:48.700 --> 00:07:51.160
client-side React app without any

00:07:51.160 --> 00:07:51.820
backend.

00:07:52.480 --> 00:07:54.520
Now this is also interesting because this

00:07:54.520 --> 00:07:57.380
actions feature is one of those features I

00:07:57.380 --> 00:07:59.760
mentioned about which we mostly

00:07:59.760 --> 00:08:03.480
heard in the context of Next.js, because

00:08:03.480 --> 00:08:06.960
Next.js actually introduced stable server

00:08:06.960 --> 00:08:10.520
actions with their latest version, Next.js

00:08:10.520 --> 00:08:14.360
14, and I do teach all about that in my

00:08:14.360 --> 00:08:17.360
Next.js course for example, but it's

00:08:17.360 --> 00:08:21.160
interesting to hear and see that it's now

00:08:21.160 --> 00:08:23.840
the React team itself on their official

00:08:23.840 --> 00:08:26.300
blog that's talking about this actions

00:08:26.300 --> 00:08:29.960
feature and that this actions feature is a

00:08:29.960 --> 00:08:33.679
feature that's not closely tied to Next.js

00:08:33.679 --> 00:08:36.679
or frameworks in general, but that

00:08:36.679 --> 00:08:39.419
instead every React developer will be

00:08:39.419 --> 00:08:42.059
able to use it, at least that client-side

00:08:42.059 --> 00:08:43.000
actions part.

00:08:43.400 --> 00:08:45.680
The server-side part will always be a bit

00:08:45.680 --> 00:08:48.340
more complex because naturally you will

00:08:48.340 --> 00:08:51.000
need a backend for that and that's

00:08:51.000 --> 00:08:54.640
exactly what a framework like Next.js or

00:08:54.640 --> 00:08:57.600
Remix gives you, but for client-side

00:08:57.600 --> 00:08:59.720
applications, single-page applications,

00:09:00.080 --> 00:09:02.560
this client-side actions part could be

00:09:02.560 --> 00:09:03.640
really interesting.

00:09:04.340 --> 00:09:06.720
Now connected to those actions we also

00:09:06.720 --> 00:09:10.420
get some new hooks which you can also

00:09:10.420 --> 00:09:13.800
already use for example if you're using

00:09:13.800 --> 00:09:16.200
Next.js because we're getting a

00:09:16.200 --> 00:09:19.120
useFormStatus and a useFormState

00:09:19.120 --> 00:09:21.660
hook which allow us to handle form

00:09:21.660 --> 00:09:23.880
submissions and update the UI based on

00:09:23.880 --> 00:09:26.740
them and so on, and a useOptimistic

00:09:26.740 --> 00:09:30.040
hook which helps with optimistic UI

00:09:30.040 --> 00:09:33.260
updates so that you can update the UI

00:09:33.260 --> 00:09:36.280
the user sees even before the data has

00:09:36.280 --> 00:09:38.260
been saved in a database, for example,

00:09:38.640 --> 00:09:41.460
to give the user the best possible super

00:09:41.460 --> 00:09:43.320
snappy user experience.

00:09:43.980 --> 00:09:46.900
So that's another really interesting

00:09:46.900 --> 00:09:50.640
feature and getting more help with form

00:09:50.640 --> 00:09:53.080
submissions and of course getting that

00:09:53.080 --> 00:09:55.320
tighter integration with the backend,

00:09:55.760 --> 00:09:57.820
these are really exciting developments

00:09:58.359 --> 00:10:00.920
which will allow React developers to

00:10:00.920 --> 00:10:03.420
build even more amazing user

00:10:03.420 --> 00:10:04.740
experiences with ease.

00:10:05.599 --> 00:10:09.260
Now one problem React suffered from,

00:10:09.400 --> 00:10:13.100
at least in my opinion, is that all these

00:10:13.100 --> 00:10:15.780
new features like React server

00:10:15.780 --> 00:10:18.920
components, for example, also were

00:10:18.920 --> 00:10:21.620
developed and published on the canary

00:10:21.620 --> 00:10:23.180
branch of React.

00:10:23.420 --> 00:10:25.680
So not on the latest stable or main

00:10:25.680 --> 00:10:28.880
branch but on a special branch or

00:10:28.880 --> 00:10:32.500
channel I should say that could be used

00:10:32.500 --> 00:10:36.640
by every React developer but not really

00:10:36.640 --> 00:10:40.880
in an easy way I would say or at least this

00:10:40.880 --> 00:10:43.960
canary branch was mainly intended to

00:10:43.960 --> 00:10:47.020
be used by framework developers which

00:10:47.020 --> 00:10:49.440
is why many of the features published

00:10:49.440 --> 00:10:52.700
through that channel were available in

00:10:52.700 --> 00:10:56.280
Next.js and were marked as stable there

00:10:56.280 --> 00:10:58.700
even though they were not marked as

00:10:58.700 --> 00:11:01.680
stable in React itself which was a bit

00:11:01.680 --> 00:11:05.000
confusing at least for me and as far as I

00:11:05.000 --> 00:11:07.400
can tell also for many other React

00:11:07.400 --> 00:11:07.940
developers.

00:11:08.900 --> 00:11:11.840
Now that will change as it seems with

00:11:11.840 --> 00:11:15.100
the next major version or at least that

00:11:15.100 --> 00:11:19.020
next major version React 19 which is

00:11:19.020 --> 00:11:22.360
about to be released later in 2024 as it

00:11:22.360 --> 00:11:26.480
seems that version seems to bundle a

00:11:26.480 --> 00:11:29.580
lot of features that have all been stuck in

00:11:29.580 --> 00:11:32.980
this canary channel for example the use

00:11:32.980 --> 00:11:35.820
client and use server directives which

00:11:35.820 --> 00:11:38.460
are needed for React server components

00:11:38.460 --> 00:11:42.660
and also server actions so that is a huge

00:11:42.660 --> 00:11:45.800
feature that's going to come to stable

00:11:45.800 --> 00:11:48.680
React though it is of course worth

00:11:48.680 --> 00:11:51.200
mentioning that if you plan on using

00:11:51.200 --> 00:11:53.800
some server-side integrations some

00:11:53.800 --> 00:11:57.060
back-end integrations you will still need

00:11:57.060 --> 00:11:59.320
some framework that gives you that

00:11:59.320 --> 00:12:03.620
integration because React itself is still a

00:12:03.620 --> 00:12:06.880
library for rendering user interfaces in

00:12:06.880 --> 00:12:08.840
the end it does not give you some

00:12:08.840 --> 00:12:11.740
server-side integration out of the box

00:12:11.740 --> 00:12:14.440
you will need to set that up on your own

00:12:14.440 --> 00:12:18.300
or use such a framework nonetheless it's

00:12:18.300 --> 00:12:22.100
nice to have it all in stable React itself in

00:12:22.100 --> 00:12:24.560
the near future and we get some other

00:12:24.560 --> 00:12:27.380
features I would guess that we get the

00:12:27.380 --> 00:12:29.540
compiler though it's not explicitly

00:12:29.540 --> 00:12:32.160
mentioned here in the blog post that it

00:12:32.160 --> 00:12:34.040
will be included in the next major

00:12:34.040 --> 00:12:37.300
version but I would guess that it is but

00:12:37.300 --> 00:12:39.900
we'll for example also get access to some

00:12:39.900 --> 00:12:43.600
new HTML elements that we can use in

00:12:43.600 --> 00:12:47.460
our code HTML elements that will allow

00:12:47.460 --> 00:12:52.340
us to easily set some head content of our

00:12:52.340 --> 00:12:55.700
site so the title or meta tags for example

00:12:55.700 --> 00:12:58.120
so that you don't need any third-party

00:12:58.120 --> 00:13:00.600
packages for that anymore but it's built

00:13:00.600 --> 00:13:03.700
into React instead we also get some new

00:13:03.700 --> 00:13:06.440
features related to asset loading so that

00:13:06.440 --> 00:13:08.620
React can help you with efficiently

00:13:08.620 --> 00:13:13.540
loading fonts or CSS files and this will all

00:13:13.540 --> 00:13:16.700
integrate with React's suspense feature

00:13:16.700 --> 00:13:19.200
so that you can show some fallback

00:13:19.200 --> 00:13:21.480
content whilst those assets are being

00:13:21.480 --> 00:13:24.720
loaded so that can be useful we get

00:13:24.720 --> 00:13:26.860
those actions which I already mentioned

00:13:26.860 --> 00:13:29.960
they are part of that stable channel then

00:13:29.960 --> 00:13:34.160
the client and server actions and it's also

00:13:34.160 --> 00:13:36.700
really interesting that Andrew Clark

00:13:37.440 --> 00:13:40.280
team member of the React team shared

00:13:40.280 --> 00:13:44.540
a tweet or a post I guess on X where he

00:13:44.540 --> 00:13:47.520
mentioned that by the end of 2024 we

00:13:47.520 --> 00:13:51.100
will likely never need these APIs so these

00:13:51.100 --> 00:13:54.500
React features again use memo use

00:13:54.500 --> 00:13:56.380
callback and memo because of that

00:13:56.380 --> 00:13:59.420
React compiler I mentioned forward ref

00:13:59.420 --> 00:14:02.280
which I didn't mention yet because refs

00:14:02.280 --> 00:14:06.080
will be accepted as standard props in

00:14:06.080 --> 00:14:08.460
React components so if you build a

00:14:08.460 --> 00:14:10.660
component that should accept the ref

00:14:10.660 --> 00:14:13.260
you will no longer need to use forward

00:14:13.260 --> 00:14:15.520
ref that seems to be another feature

00:14:15.520 --> 00:14:18.960
that's coming with React 19 as it seems

00:14:18.960 --> 00:14:23.140
React lazy should be made obsolete by

00:14:23.140 --> 00:14:26.800
React server components and we'll also

00:14:26.800 --> 00:14:29.680
get another new function the use

00:14:29.680 --> 00:14:34.700
function I guess also with React 19 which

00:14:34.700 --> 00:14:38.020
can be used to access context instead of

00:14:38.020 --> 00:14:41.160
use context but which can also be used

00:14:41.160 --> 00:14:44.880
to handle promises and build async

00:14:44.880 --> 00:14:48.240
await like React components even if

00:14:48.240 --> 00:14:50.100
you're not using React server

00:14:50.100 --> 00:14:52.560
components because at the moment

00:14:52.560 --> 00:14:56.780
with React 18 there indeed are async

00:14:56.780 --> 00:14:59.120
components so components that can be

00:14:59.120 --> 00:15:01.640
decorated with async await but we're

00:15:01.640 --> 00:15:03.680
talking about server components here

00:15:03.680 --> 00:15:05.640
so components that are rendered on the

00:15:05.640 --> 00:15:08.320
server client only components on the

00:15:08.320 --> 00:15:11.100
other hand can't use async await and

00:15:11.100 --> 00:15:13.400
that's where this use function also

00:15:13.400 --> 00:15:15.840
seems to come in the idea with that

00:15:15.840 --> 00:15:19.960
essentially use also works a bit like await

00:15:19.960 --> 00:15:23.300
and allows you to wait for a promise and

00:15:23.300 --> 00:15:25.600
for the data that's produced by that

00:15:25.600 --> 00:15:28.160
promise in client only components

00:15:28.160 --> 00:15:31.320
which also is another nice feature and

00:15:31.320 --> 00:15:34.920
therefore React 19 really is an upcoming

00:15:34.920 --> 00:15:38.080
React version to be excited about and I

00:15:38.080 --> 00:15:40.740
can't wait to see what we can build with

00:15:40.740 --> 00:15:43.680
that version and of course it should go

00:15:43.680 --> 00:15:46.860
without mentioning that I will keep my

00:15:46.860 --> 00:15:50.360
React course updated as soon as there is

00:15:50.360 --> 00:15:52.220
something to be updated and added

00:15:52.220 --> 00:15:55.940
and that I will try my very best to give all

00:15:55.940 --> 00:15:58.040
my students the best possible learning

00:15:58.040 --> 00:15:59.580
experience in that course.