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 reference is not stable between renders. #309

Closed
salmanorak opened this issue Dec 18, 2023 · 4 comments · Fixed by #314
Closed

T function reference is not stable between renders. #309

salmanorak opened this issue Dec 18, 2023 · 4 comments · Fixed by #314
Labels
bug Something isn't working

Comments

@salmanorak
Copy link

salmanorak commented Dec 18, 2023

Describe the bug
The reference of t function that returns from useI18n and useScopedI18n is not stable.

To Reproduce
reproduce:

Expected behavior
The reference of the t function should be stable so it will not cause a re-calculate when it is used in any hook dependency array.

Screenshots
after each re-render the useEffect that has only t function dependency is refiring.
image

About (please complete the following information):

  • next-international version [1.1.4]
  • Next.js version [e.g. 14.0.1]

Workaround

For know I have wrapped the function with one useState hook.

import { useState } from 'react';
import { useI18n } from '@/locale';

export const useTranslate = () => {
  const [t] = useState<ReturnType<typeof useI18n>>(() => useI18n());

  return t;
};
@salmanorak salmanorak added the bug Something isn't working label Dec 18, 2023
@salmanorak
Copy link
Author

@QuiiBz thansk for fix. When You are planing the release with fixes?

@QuiiBz
Copy link
Owner

QuiiBz commented Dec 23, 2023

I'd like to merge #316 that fixes another issue before landing a new release.

@maloyuso
Copy link

maloyuso commented Jan 8, 2024

Hi! @QuiiBz Is there a date to expect the release of a new version including this fix?
Thanks 👌

@QuiiBz
Copy link
Owner

QuiiBz commented Jan 8, 2024

Sorry for the delay - https://github.com/QuiiBz/next-international/releases/tag/1.2.0 has been published!

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

Successfully merging a pull request may close this issue.

3 participants