use-page-leave

Calls given function when mouse leaves the page

Import

Usage

use-page-leave calls given function when mouse leaves the page:

Mouse left the page 0 times

import { useState } from 'react';
import { usePageLeave } from '@mantine/hooks';

function Demo() {
  const [leftsCount, setLeftsCount] = useState(0);
  usePageLeave(() => setLeftsCount((p) => p + 1));
  return <>Mouse left the page {leftsCount} times</>;
}

Definition

function usePageLeave(onPageLeave: () => void): void;