mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Fix randomized titles getting new title on rerender
This commit is contained in:
parent
1217bae7ee
commit
91a24607a7
1 changed files with 3 additions and 3 deletions
|
@ -6,13 +6,13 @@ const shouldGiveJokeTitle = () => Math.floor(Math.random() * 10) === 0;
|
||||||
|
|
||||||
export function useRandomTranslation() {
|
export function useRandomTranslation() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const shouldJoke = useMemo(() => shouldGiveJokeTitle(), []);
|
||||||
const seed = useMemo(() => Math.random(), []);
|
const seed = useMemo(() => Math.random(), []);
|
||||||
|
|
||||||
const getRandomTranslation = useCallback(
|
const getRandomTranslation = useCallback(
|
||||||
(key: string): string => {
|
(key: string): string => {
|
||||||
const shouldRandom = shouldGiveJokeTitle();
|
|
||||||
const defaultTitle = t(`${key}.default`) ?? "";
|
const defaultTitle = t(`${key}.default`) ?? "";
|
||||||
if (!shouldRandom) return defaultTitle;
|
if (!shouldJoke) return defaultTitle;
|
||||||
|
|
||||||
const keys = t(`${key}.extra`, { returnObjects: true });
|
const keys = t(`${key}.extra`, { returnObjects: true });
|
||||||
if (Array.isArray(keys)) {
|
if (Array.isArray(keys)) {
|
||||||
|
@ -22,7 +22,7 @@ export function useRandomTranslation() {
|
||||||
|
|
||||||
return typeof keys === "string" ? keys : defaultTitle;
|
return typeof keys === "string" ? keys : defaultTitle;
|
||||||
},
|
},
|
||||||
[t, seed]
|
[t, seed, shouldJoke]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { t: getRandomTranslation };
|
return { t: getRandomTranslation };
|
||||||
|
|
Loading…
Reference in a new issue