UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

27 lines (26 loc) 858 B
import { useEffect, useState } from 'react'; import { isSSR } from '@atlaskit/editor-common/core-utils'; /** * ExcludeFromHydration component delays rendering of its children until after the initial * hydration phase. It renders the fallback during SSR/hydration and children after. * @param children - The content to render after hydration * @param fallback - Optional fallback content to render during hydration (e.g., a placeholder to prevent layout shift) * @returns */ function ExcludeFromHydration({ children, fallback = null }) { const [shouldRender, setShouldRender] = useState(false); useEffect(() => { if (isSSR()) { return; } setShouldRender(true); }, []); if (!shouldRender) { return fallback !== null && fallback !== void 0 ? fallback : null; } return children; } export default ExcludeFromHydration;