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

i18n function is not referentially stable #2

Open
peeke opened this issue Jul 6, 2021 · 5 comments
Open

i18n function is not referentially stable #2

peeke opened this issue Jul 6, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@peeke
Copy link

peeke commented Jul 6, 2021

useI18n() returns a different function each time it's called. This makes it hard to use the i18n function inside a useEffect.

@peeke peeke added the bug Something isn't working label Jul 6, 2021
@EECOLOR
Copy link
Member

EECOLOR commented Jul 6, 2021

Do you have an example of an effect where you would want to use i18n?

@peeke
Copy link
Author

peeke commented Jul 6, 2021

I had a useEffect, where I wanted to use i18n inside. Had to pass the i18n as a dependency, or store it in a ref (which felt a bit hacky). Ended up taking a different route altogether, but it felt like something that should maybe be possible.

@EECOLOR
Copy link
Member

EECOLOR commented Jul 7, 2021

I agree it should be possible. While thinking about it I wondered of a use case where you would need i18n in an effect. Rendering usually happens in the 'render' function, so it might indicate unneeded complexity.

@peeke
Copy link
Author

peeke commented Jul 7, 2021

That is what actually was the case, and I fixed it by doing exactly that. We could also just note the fact that it isn't referentially stable in the docs.

@EECOLOR
Copy link
Member

EECOLOR commented Jul 7, 2021

I actually think it should be referentially more stable. So I would vote to add a useCallback around it.

That said, we should probably use it as a potential red flag when we see it used inside another hook during reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants