UNPKG

next-i18next

Version:

The easiest way to translate your NextJs apps.

26 lines (25 loc) 1.03 kB
import { useEffect, useLayoutEffect } from "react"; //#region src/pagesRouter/utils.ts const getFallbackForLng = (lng, fallbackLng) => { if (typeof fallbackLng === "string") return [fallbackLng]; if (Array.isArray(fallbackLng)) return fallbackLng; if (typeof fallbackLng === "object") { const fallbackList = fallbackLng[lng]; const fallbackDefault = fallbackLng.default; return [...fallbackList ?? [], ...fallbackDefault ?? []]; } if (typeof fallbackLng === "function") return getFallbackForLng(lng, fallbackLng(lng)); return []; }; const unique = (list) => Array.from(new Set(list)); /** * This hook behaves like `useLayoutEffect` on the client, * and `useEffect` on the server(no effect). * * Since using `useLayoutEffect` on the server cause warning messages in nextjs, * this hook is workaround for that. */ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect; //#endregion export { getFallbackForLng, unique, useIsomorphicLayoutEffect }; //# sourceMappingURL=utils.mjs.map