import { useEffect, useRef } from 'react'; // Shared is-mounted guard for async callbacks (#578). A monotonic `seqRef` drops a STALE response // (an older request resolving after a newer one) but says nothing about whether the component is // still there: a fetch that resolves after unmount still matches the latest seq and still calls // setState. Read `ref.current` in every async callback alongside the seq check. // // The flag is (re-)armed inside the effect rather than only at `useRef` init so a StrictMode // double-invoke — mount, unmount, remount on the same instance — leaves it true. export function useIsMountedRef(): { readonly current: boolean } { const ref = useRef(true); useEffect(() => { ref.current = true; return () => { ref.current = false; }; }, []); return ref; }