This is a record 前端面试的话术集锦第十四篇博文——高频考点(React常考基础知识点)
and I will keep updating this blog post. ❗❗❗
1. Life cycle
V16
Mechanism introduced in version Fiber
. This mechanism affects some life cycle calls to a certain extent, and also introduces new 2
ones API
to solve problems.
In previous versions, if you had a very complex composite component and then changed the top-level component state
, the call stack could be very long.
If the call stack is too long, coupled with complex operations in the middle, it may cause the main thread to be blocked for a long time, resulting in a bad user experience. This Fiber
problem was created to solve this problem.
Fiber
It is essentially a virtual stack frame. The new scheduler will freely schedule these frames according to priority, thus changing the previous synchronous rendering to asynchronous rendering, and calculating updates in segments without affecting the experience.
React
There is its own set of logic for how to distinguish priorities . For animations that are very real-time, that is, if 16 ms
they must be rendered once to ensure that there is no lag, the update React
will 16 ms(以内)
be paused every time and returned to continue rendering the animation.
For asynchronous rendering, there are now two stages of rendering: reconciliation
and commit
. The former process can be interrupted, while the latter cannot be paused and the interface will be updated until it is completed.
1.1 Reconciliation stage
-
componen