useScrollTrigger
Fires when the user scrolls past a percentage of the page. Pass onOpenChange to update your popup's open state. The hook listens to the window scroll event and calls onOpenChange(true) once the threshold is crossed.
$import { useScrollTrigger } from react-marketing-popups
Signature
useScrollTrigger({ percent?, onOpenChange? })
Returns
readonly [boolean, Dispatch<SetStateAction<boolean>>]Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| percent | number | 50 | Page scroll depth (0–100) at which the trigger fires |
| onOpenChange | (v: boolean) => void | — | Called with true when the scroll threshold is crossed. Wire to your popup's open state setter. |
Returns
fired
boolean — whether the trigger has fired. Starts as false, becomes true once the scroll threshold is crossed.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 scroll threshold is crossed. Manage popup visibility separately with useState.
Loading...Scroll depth strategy
Choose the percentage based on what the user should have read or seen before the popup appears.
Loading...Combined with usePersistence
Show the popup only once so a returning visitor who already scrolled the page is not shown it again.
Loading...