mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🚑 fix: Prevent Infinite Re-Rendering of the Password Reset UI (#2887)
* 🔧 fix: prevent unnecessary re-rendering of components using useLocalize hook The useLocalize hook now uses useCallback to create a memoized version of the localize function. This will prevent unnecessary recalculations when the language value changes. * 🚑 fix: not reset the bodyText if it has a value set.
This commit is contained in:
parent
5dc5d875ba
commit
0ee060d730
2 changed files with 12 additions and 1 deletions
|
|
@ -36,6 +36,9 @@ function RequestPasswordReset() {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (bodyText) {
|
||||
return;
|
||||
}
|
||||
if (!requestPasswordReset.isSuccess) {
|
||||
setHeaderText('com_auth_reset_password');
|
||||
setBodyText(undefined);
|
||||
|
|
@ -64,6 +67,7 @@ function RequestPasswordReset() {
|
|||
resetLink,
|
||||
localize,
|
||||
setHeaderText,
|
||||
bodyText,
|
||||
]);
|
||||
|
||||
if (bodyText) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { localize } from '~/localization/Translation';
|
||||
import store from '~/store';
|
||||
|
||||
export default function useLocalize() {
|
||||
const lang = useRecoilValue(store.lang);
|
||||
return (phraseKey: string, ...values: string[]) => localize(lang, phraseKey, ...(values ?? []));
|
||||
|
||||
const memoizedLocalize = useCallback(
|
||||
(phraseKey: string, ...values: string[]) => localize(lang, phraseKey, ...(values ?? [])),
|
||||
[lang], // Only recreate the function when `lang` changes
|
||||
);
|
||||
|
||||
return memoizedLocalize;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue