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

t function returned from useTranslation is not properly memoized #1224

Open
rdenman opened this issue Aug 20, 2024 · 1 comment
Open

t function returned from useTranslation is not properly memoized #1224

rdenman opened this issue Aug 20, 2024 · 1 comment

Comments

@rdenman
Copy link

rdenman commented Aug 20, 2024

What version of this package are you using?
15.3.1

What operating system, Node.js, and npm version?
MacOS, node 20, npm 10

What happened?
When the t function returned from useTranslation is included in a dependency array, the result is infinite rerenders. It appears the function is not memoized properly.

What did you expect to happen?
Including t in a dependency array should not result in infinite rendering.

Are you willing to submit a pull request to fix this bug?

@MonstraG
Copy link
Contributor

MonstraG commented Oct 4, 2024

This happens to me only if t is a dependency array of a useEffect that does Router.push (or replace).

Lazy workaround:

	const tRef = useRef<Translate>(t);
	tRef.current = t;

and then use the tRef.current("afasfas") in your hooks.

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