Recently, while refactoring a project at my company, I tried some things and found that I didn’t really understand React’s rendering mechanism and when render
would be triggered. Later, I found that not only me, but many people were not familiar with the whole mechanism, so I decided to write this article to share my experience.
Actually, it’s not too bad if you don’t know how to optimize, but the worse thing is that you think you’re optimizing, but you’re actually slowing down performance, and the root cause is that you’re not familiar enough with the whole mechanism of React. The “optimized” component is slower! This is serious.
Therefore, this article will cover the following topics:
- The difference between
Component
andPureComponent
- The role of
shouldComponentUpdate
- React’s rendering mechanism
- Why use Immutable data structures
To determine how much you understand the above, let’s take a few quizzes right away! Some of them have traps, so please keep your eyes open!