Skip to content
Entangle UI v0.13.0

useIsMounted

useIsMounted(): () => boolean

Defined in: src/hooks/useIsMounted/useIsMounted.ts:30

Returns a stable getter that reports whether the component is still mounted. Call it inside async continuations (promises, timers, fetches) before committing state, so a resolution that lands after unmount becomes a no-op instead of a “set state on an unmounted component” warning.

The getter identity is stable for the component lifetime, so it is safe to include in — or omit from — dependency arrays without churn. It reports false until the mount effect commits and false again after unmount, which also covers the double mount/unmount of React StrictMode.

Prefer real cancellation (AbortController, effect cleanup) where the async source supports it; reach for this only when the source cannot be cancelled.

() => boolean

const isMounted = useIsMounted();
useEffect(() => {
void load().then(data => {
if (isMounted()) setData(data);
});
}, [isMounted]);