Hello everyone, I'm Casson.
On March 29, 2022, the React18
official version was released.
From the v16
beginning, the React
team has been popularizing 并发
the concept. In v18
the iterative process (alpha, Beta, RC), science has also been popularized 并发特性
, so when the official version is released, there are no new features.
This article focuses on v18
some future trends revealed in the release log.
Welcome to join the human high-quality front-end framework research group , with flying
Developers may not be exposed to concurrency features
React
API
Be cautious about increasing . From its birth in 2013 to the present, the way to trigger updates is the same this.setState
.
After the introduction of 并发
concepts, there are several 并发
related ones, such as:API
-
useTransition
-
useDeferredValue
There are even 并发
basic ones API
(that is, in the case of concurrency, not using these APIs may cause bugs), such as:
-
useSyncExternalStore
-
useInsertionEffect
There are so many more at once API
, but it is useState
not impossible to not use it API
. Moreover, 并发
this feature is somewhat unfamiliar to most front-end developers.
并发特性
You can think about how difficult it is for developers to get started using it in your own business .
Therefore, developers may not be exposed to concurrency featuresv18
in applications developed in the future . 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.
这一API
很可能会由各种Router
实现,再作为一个配置项开放给开发者。
万物皆可Suspense
对于React
来说,有两类瓶颈需要解决:
-
CPU的瓶颈,如大计算量的操作导致页面卡顿
-
IO的瓶颈,如请求服务端数据时的等待时间
其中CPU的瓶颈
通过并发特性
的优先级中断机制解决。
IO的瓶颈
则交给Suspense
解决。
所以,未来一切与IO
相关的操作,都会收敛到Suspense
这一解决方案内。
从最初的React.lazy
到如今仍在开发中的Server Components
,最终万物皆可Suspense
。
这其中有些逻辑是很复杂的,比如:
-
Server Components
-
新的服务端渲染方案
所以,这些操作不大可能是直接面向开发者的。
这又回到了上一条,这些操作会交由各种库实现。如果复杂度更高,则会交由基于React
封装的框架实现,比如Next.js
、Remix
。
这也是为什么React团队
核心人物Sebastian
会加入Next.js
。
可以说,React
未来的定位是:一个前端底层操作系统,足够复杂,一般开发者慎用。
而开发者使用的是基于该操作系统实现的各种上层应用。
总结
如果说v16
之前各种React Like
库还能靠体积、性能优势分走React
部分蛋糕,那未来两者走的完全是两条赛道,因为两者的生态不再兼容。
未来不再会有React全家桶
的概念,桶里的各个部件最终会沦为更大的框架中的一个小模块。
Do you currently use it directly in your business React
, or do you use various frameworks (for example Next.js
)?