mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +01:00
* 🔧 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.
15 lines
478 B
TypeScript
15 lines
478 B
TypeScript
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);
|
|
|
|
const memoizedLocalize = useCallback(
|
|
(phraseKey: string, ...values: string[]) => localize(lang, phraseKey, ...(values ?? [])),
|
|
[lang], // Only recreate the function when `lang` changes
|
|
);
|
|
|
|
return memoizedLocalize;
|
|
}
|