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

The translate function as a stable reference #7

Open
gorandalum opened this issue Nov 3, 2023 · 0 comments
Open

The translate function as a stable reference #7

gorandalum opened this issue Nov 3, 2023 · 0 comments

Comments

@gorandalum
Copy link

gorandalum commented Nov 3, 2023

We in AtB (the transport company in Trøndelag, Norway) actually use this library for the translations in our app.

Sometimes we translate something in a hook, and then we come into the situation where we need t in the dependency array to make the exhaustive-deps rule happy, but the t function is not a stable reference.

Would it be possible to use useCallback on the creation of the t function? By changing

return {
  t: (arg: any) => arg[language],
  language,
}

into

return {
  t: useCallback((arg: any) => arg[language], [language]),
  language,
}

I can create a PR if you think this is an ok change.

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

1 participant