Hacker News new | ask | show | jobs
by acemarke 2365 days ago
The primary point of hooks was to give function components the same capabilities that classes already had. In that respect, letting classes use hooks would have been superfluous.

At the same time, the React team _could_ have chosen to implement support for hooks in classes, but chose not to, both for simplicity and as a carrot to encourage folks to use function components where possible. Based on the discussions and examples I've seen, capabilities like Concurrent Mode and Fast Refresh work better with function components because there's fewer edge cases to worry about. While classes aren't going away in the foreseeable future, there's valid reasons to try to get the community to adopt function components more.

1 comments

Well, as far as my understanding of hooks go, and please do correct me if I'm wrong, hooks are not just about giving functional component an option to use state and lifecycle methods. They are also a much more powerful and flexible replacement of mixins and offer an (arguably better) alternative to use certain design patterns, like render props.

I did assume that hooks were not supported in classes because it would be too complex to support that use-case, but the linked article specifically has an "Absorb the Complexity" principle, so it seemed a bit weird to me. Also, I understand the decision to try to motivate the community to use function components more, but is this the trend that we can expect to continue seeing in React? Certain APIs being phased out until they finally become deprecated. I know it has happened a few times already in React, but not on the level of something like a class API.