useInactivityTrigger
Fires after the user has been idle for a given duration. Pass onOpenChange to update your popup's open state. Inactivity is measured by the absence of mouse movement and key presses — the timer resets on any interaction.
$import { useInactivityTrigger } from react-marketing-popups
Signature
useInactivityTrigger({ ms?, onOpenChange? })
Returns
readonly [boolean, Dispatch<SetStateAction<boolean>>]Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| ms | number | 30000 | Milliseconds of inactivity required before the trigger fires. The timer resets on any mouse or keyboard event. |
| onOpenChange | (v: boolean) => void | — | Called with true when the idle period elapses. Wire to your popup's open state setter. |
Returns
fired
boolean — whether the trigger has fired. Starts as false, becomes true after the idle period elapses without interaction.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 the idle period elapses. Manage popup visibility separately with useState.
Loading...Choosing the right idle time
Shorter durations are more aggressive; longer durations target genuinely disengaged users.
Loading...Combined with usePersistence
Avoid showing the popup every time a user pauses on a page they visit repeatedly.
Loading...