-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why isn't this included with React? #2
Comments
@FrobtheBuilder thank you! |
I also think it’s an awesome library. It’s made keeping a mixed functional/classes codebase easy. |
It's a funny thing, when I first read about how React hooks work I figured that there should be no reason they couldn't be used in class component render methods, since internally those are still just being called as functions and hooks are simply a means of keeping state in an external list and referencing it in the body of a function. It came as a real surprise to learn that they weren't supported there for no discernible reason, even just for compatibility purposes with libraries. Of course it WAS possible, just a matter of somebody adding that functionality, yet nobody ever thought to do it except @salvoravida. The official hooks documentation literally states that you shouldn't bother to refactor all your class components to use hooks since they're not dropping support any time soon, but you just can't use the feature without doing that. |
By the way, I made an issue for this in the main React repository: facebook/react#16116. Upvote it if you'd like to see this added. |
I thought this was too good to be true. We've got a codebase full of class components that we're currently localizing with i18next, but we didn't want to resort to wrapping everything with a HOC. The translation hook shipped with react-i18next seems to work perfectly with the built-in React hooks shimmed using this library and we can literally just call
useTranslation
in our class render methods, as long as we're careful to follow the ordinary hook rules. This library of yours is an absolute lifesaver and I'm shocked that it isn't more popular. It also makes me wonder why in the name of all that is holy that the React team didn't include this compatibility layer in the core of React.Thank you so much for making this thing. I am forever in your debt.
The text was updated successfully, but these errors were encountered: