useExitTrigger
Fires when the user's mouse moves toward the top of the viewport — the classic exit-intent signal. Pass onOpenChange to update your popup's open state. By default it fires once per page load and only on desktop (no mouse on touch devices).
$import { useExitTrigger } from react-marketing-popups
Signature
useExitTrigger(opts?: { topZonePx?: number; delayMs?: number; once?: boolean; onOpenChange?: (v: boolean) => void })
Returns
readonly [boolean, Dispatch<SetStateAction<boolean>>]Parameters
| Option | Type | Default | Description |
|---|---|---|---|
| topZonePx | number | 50 | Pixel height of the top-of-viewport zone that triggers the intent detection |
| delayMs | number | 0 | How long the mouse must remain in the zone before firing — debounces accidental triggers |
| once | boolean | true | When true the trigger fires only once per page load; set to false to re-fire on each exit movement |
| onOpenChange | (v: boolean) => void | — | Called with true when exit intent is detected. Wire to your popup's open state setter. |
Returns
fired
boolean — whether the trigger has fired. Starts as false, becomes true when exit intent is detected.setFired
Dispatch<SetStateAction<boolean>> — rarely needed directly; the hook manages this internally. Use a separate useState for popup visibility.Code Examples
By design the open state is handled outside of the component
Basic usage
Pass onOpenChange to set your open state when exit intent is detected. Manage popup visibility separately with useState.
Loading...Configuring the options
All options are optional. Tune topZonePx to control sensitivity and delayMs to debounce accidental triggers.
Loading...Combined with usePersistence
Prevent repeat interruptions for visitors who have already dismissed the popup.
Loading...