5 ms·
I wonder if React has had any impact on people's general tendency for reaching for classes vs. closures, particularly after hooks were introduced.
by bduffany 3y ago
I wonder if React has had any impact on people's general tendency for reaching for classes vs. closures, particularly after hooks were introduced.
- moritzwarhier 3y agoThing is, hook state looks like closures, but it's not the same at all. The machinery behind the scenes might be ugly, but this syntax is also what I love about React Hooks. I was preferring closures to ES6 classes before using React, despite the performance implications. Since switching to TypeScript I also like ES classes though. Especially for things like MobX... but even without it. Regardless of React, I feel like classes are the context where getters and setters feel most natural and ergonomic. And classes are great for grouping state and behavior in an easy-to-understand way.
- nurple 3y agoI think it made using classes more popular before hooks, and drove--along with functional components--the more general popularity of functional style of js afterwards. I feel like the latter are the idioms you will find most common in modern code, docs, and training today; though class components are still fully supported.