2.2. Deriving all hooks from lifecycle #
Created Tuesday 06 February 2022
Why #
It’s simple to derive lifecycle methods after considering the lifecycle of a React component.
How #
There are 2 steps to derive/understand hooks:
- Consider all possible hooks w.r.t lifecycle phases - places where state could be changed/set for rendering.
- Remove duplicate and unneeded hooks.
After doing this, only 3 hooks remain, namely:
componentDidMount
componentWillUnmount
componentDidUpdate
All other hooks, as said, are either unnecessary (they do nothing) or duplicate (can be replaced by existing hook).
What #
Here’s the lifecycle and hooks derivation, HD photo: MEGA link The result is this.