Why isn't this included with React?
FrobtheBuilder opened this issue · 4 comments
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.
@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.