본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

useMounted — 마운트 훅

원문 보기 위키 갱신

SSR에 안전한 플래그로, 컴포넌트가 클라이언트에서 마운트되면 true로 바뀌어요.

출처: 문서

본문

사용법 (Usage)

import { useMounted } from '@primereact/hooks/use-mounted';
const mounted = useMounted();

if (!mounted) return null;

return <ClientOnlyContent />;

하이드레이션 불일치를 일으키지 않고 브라우저 API에 의존하는 콘텐츠를 게이트할 때 유용해요.

옵션 (Options)

useMounted({
    onMounted: () => console.log('mounted'),
    onUnmounted: () => console.log('unmounted')
});

두 콜백 모두 선택 사항이에요.

시그니처 (Signature)

function useMounted(options?: { onMounted?: () => void; onUnmounted?: () => void }): boolean;

더 알아보기 (Learn more)