Skip to content
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

Closed
FrobtheBuilder opened this issue Jul 9, 2019 · 4 comments
Closed

Why isn't this included with React? #2

FrobtheBuilder opened this issue Jul 9, 2019 · 4 comments

Comments

@FrobtheBuilder
Copy link

FrobtheBuilder commented Jul 9, 2019

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.

@salvoravida
Copy link
Owner

@FrobtheBuilder thank you!

@KaySackey
Copy link

I also think it’s an awesome library. It’s made keeping a mixed functional/classes codebase easy.

@FrobtheBuilder
Copy link
Author

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.

@FrobtheBuilder
Copy link
Author

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.

@salvoravida salvoravida pinned this issue Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants