42 ms·
I like React Hooks, I like the simplicity. I dislike that it makes reading the code much more difficult. The code required to do a simple "componentDidMount()"
by mmcnl 7y ago
I like React Hooks, I like the simplicity. I dislike that it makes reading the code much more difficult. The code required to do a simple "componentDidMount()" is very abstract. It is difficult to reason about what a component does at first glance, with the class methods this is much easier.
- city41 7y agoclass components have a huge downside in that `this` is mutable. Hooks solve this problem, and this problem seems to have motivated their creation to some extent. This blog post goes into more detail: https://overreacted.io/how-are-function-components-different-from-classes/ https://overreacted.io/how-are-function-components-different...
- ArchReaper 7y agoTo do 'componentDidMount' you simply need a 'useEffect' with an empty (non-null) dependency array. It makes sense to me - maybe the issue is more familiarity than simplicity? Edit: useEffect performs a side effect every time one of it's dependencies has changed value. Passing an empty array means the effect is only run once (on mount) because there are no dependencies.