3 ms·
That didn't require the meta language and rules of hooks though, they could have added this.addEffect(callback, deps) or something to class components. To prese
by esprehn 4y ago
That didn't require the meta language and rules of hooks though, they could have added this.addEffect(callback, deps) or something to class components. To preserve back compat they could have added a new base class you inherit from to get access to new APIs.
Most of hooks could have been done incrementally on top of classes.
- phailhaus 4y agoImagine trying to debug a component that both has lifecycle methods and reactive hooks? That would be a total nightmare, especially when the same state is being updated in both places (because that would have to be allowed). Going all-in on hooks means that there are two distinct, independent ways of writing components, and you never have to deal with interactions between the two. I also don't think this would be possible. Hooks are based on closures and injected state, which you can't do in a class since separate methods won't share the closure.
- esprehn 4y agoOnly if you're constrained by the existing API of hooks. Preact signals is a good example of how class components could have been improved with reactivity: https://twitter.com/_developit/status/1567272951136788481 https://twitter.com/_developit/status/1567272951136788481