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

Split out useTranslationAppDir from the useTranslation hook into its own exported regular function #1149

Closed
PhilipAngelinNE opened this issue Sep 27, 2023 · 3 comments

Comments

@PhilipAngelinNE
Copy link

PhilipAngelinNE commented Sep 27, 2023

What version of this package are you using?
2.0.5

What problem do you want to solve?
Cut out the useTranslationAppDir logic from the useTranslation hook in app directory RSC, and put it in another exported regular function (e.g import t from "next-translate/appdir").

React hooks aren't allowed in RSC, so it's misleading having this hook just magically work entirely different (not using state or React hooks even) when in app directory environment.

At first of course I thought that the hook shouldn't work in my RSC, but it does. It's not intuitive and developers shouldn't need to read the source code to get an idea what the hook actually does.

What do you think is the correct solution to this problem?
If I was in charge, I would keep the useTranslation hook as is, and split out the app directory logic into a custom function, because there's no reason for that logic to be in a hook. It's stateless and has nothing to do with React, it's just using a bunch of globals and other internal variables.

Are you willing to submit a pull request to implement this change?
If you don't feel like it, I could give it a go.

@aralroca
Copy link
Owner

ok done @PhilipAngelinNE ! I created the createTranslation helper that is possible to use in app dir without being a hook

@aralroca
Copy link
Owner

I prefer to return the t function and also the lang instead of only the t function, also because the t function depends on the language. But at least now is not more a hook to work fine in RSC

@PhilipAngelinNE
Copy link
Author

I prefer to return the t function and also the lang instead of only the t function, also because the t function depends on the language. But at least now is not more a hook to work fine in RSC

I agree, that'd be better than my given example.

Thanks for the quick response and improvement, can't wait to update and try the new helper out!

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

2 participants