Hello, I’m Carson.
March 29, 2022,React18
Official release.
fromv16
Start,React
The team is becoming popularConcurrent
The concept of. stayv18
In the iterative process of (alpha, beta, RC), it has also been popular scienceConcurrency characteristics
Therefore, when the official version was released, there were no new features.
This article mainly explainsv18
Some future trends revealed in the release log.
Welcome to join the human high-quality front-end frame group and fly with us
Developers may not be exposed to concurrency features
React
To increaseAPI
Is very cautious. Since its birth in 13 years, the way to trigger the update isthis.setState
。
And introduceConcurrent
After the concept, light is andConcurrent
dependentAPI
There are several, such as:
- useTransition
- useDeferredValue
Even appeared forConcurrent
BottomlessAPI
(that is, in the case of concurrency, there may be bugs if these APIs are not used), for example:
- useSyncExternalStore
- useInsertionEffect
So much more at onceAPI
, not likeuseState
This can’t be usedAPI
, besides,Concurrent
This feature is a little strange to most front-end developers.
You can substitute your own business and let developers use itConcurrency characteristics
How hard it is.
So, in the futurev18
Developed applications,Developers may not be exposed to concurrency features。 These features are more likely to be encapsulated by various libraries.
For example:startTransition
It allows users to switch between different views without blocking user input.
ThisAPI
It is likely to beRouter
Implementation, and then open to developers as a configuration item.
Everything can be suspended
aboutReact
Generally speaking, there are two kinds of bottlenecks to be solved:
- CPU bottlenecks, such as page jams caused by large amount of computing operations
- The bottleneck of IO, such as the waiting time when requesting data from the server
amongCPU bottleneck
adoptConcurrency characteristics
Priority interrupt mechanism.
Bottleneck of IO
Give it toSuspense
solve.
So, everything in the futureIO
Relevant operations will converge toSuspense
Within this solution.
From the initialReact.lazy
Still under developmentServer Components
In the end, everything can beSuspense
。
Some of the logic is very complex, such as:
- Server Components
- New server-side rendering scheme
Therefore, these operations are unlikely to be directed to developers.
This goes back to the previous article. These operations will be implemented by various libraries. If the complexity is higher, it will be based onReact
Encapsulated framework implementation, such asNext.js
、Remix
。
That’s whyReact team
Key figuresSebastian
Will joinNext.js
。
so to speak,React
The future positioning is: a front-end underlying operating system, which is complex enough for general developers to use with caution.
And developers useVarious upper layer applications based on the operating system。
summary
ifv16
Various beforeReact Like
The library can also be separated by volume and performance advantagesReact
For some cakes, in the future, the two will take completely two tracks, because the ecology of the two is no longer compatible.
There will be no more in the futureReact family bucket
The components in the bucket will eventually become a small module in a larger framework.
At present, it is used directly in your businessReact
Or use various frameworks (such asNext.js
)?