18 lines
509 B
TypeScript
18 lines
509 B
TypeScript
import { useSyncExternalStore } from "react";
|
|
|
|
const emptySubscribe = () => () => {};
|
|
|
|
/**
|
|
* useMounted — false during SSR and the first client render, true thereafter.
|
|
* Uses useSyncExternalStore (not an effect), so it's safe for gating
|
|
* client-only work like createPortal without tripping the
|
|
* set-state-in-effect rule. Mirrors the pattern in components/logo.tsx.
|
|
*/
|
|
export function useMounted(): boolean {
|
|
return useSyncExternalStore(
|
|
emptySubscribe,
|
|
() => true,
|
|
() => false,
|
|
);
|
|
}
|