mirror of
https://github.com/zoriya/v10.git
synced 2026-08-10 16:09:18 +00:00
28 lines
903 B
JavaScript
28 lines
903 B
JavaScript
import { useLayoutEffect, useReducer, useRef } from "react";
|
|
//#region src/i18n/use-lang-root-element.ts
|
|
function useLangRootElement(langRootRef, parentAddLocaleRoot) {
|
|
const [, invalidateLangRoot] = useReducer((epoch) => epoch + 1, 0);
|
|
const langRootElementRef = useRef(null);
|
|
useLayoutEffect(() => {
|
|
if (!langRootRef) return;
|
|
return parentAddLocaleRoot?.();
|
|
}, [langRootRef, parentAddLocaleRoot]);
|
|
useLayoutEffect(() => {
|
|
if (!langRootRef) {
|
|
if (langRootElementRef.current !== null) {
|
|
langRootElementRef.current = null;
|
|
invalidateLangRoot();
|
|
}
|
|
return;
|
|
}
|
|
const node = langRootRef.current;
|
|
if (node === langRootElementRef.current) return;
|
|
langRootElementRef.current = node;
|
|
invalidateLangRoot();
|
|
});
|
|
return langRootElementRef.current ?? langRootRef?.current ?? null;
|
|
}
|
|
//#endregion
|
|
export { useLangRootElement };
|
|
|
|
//# sourceMappingURL=use-lang-root-element.js.map
|