The official version of React18 is released, what is the future development trend?

Hello everyone, I'm Casson.

On March 29, 2022, the React18official version was released.

From the v16beginning, the Reactteam has been popularizing 并发the concept. In v18the 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 v18some 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

ReactAPIBe 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 useStatenot 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, startTransitionit 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.jsRemix

这也是为什么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)?

Guess you like

Origin juejin.im/post/7080719159645962271