You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `useOnInViewChanged` hook provides a more direct alternative to `useInView`. It takes a callback function and returns a ref that you can assign to the DOM element you want to monitor. When the element enters the viewport, your callback will be triggered.
256
+
The `useOnInView` hook provides a more direct alternative to `useInView`. It takes a callback function and returns a ref that you can assign to the DOM element you want to monitor. When the element enters the viewport, your callback will be triggered.
257
257
258
258
Key differences from `useInView`:
259
259
- **No re-renders** - This hook doesn't update any state, making it ideal for performance-critical scenarios
260
260
- **Direct element access** - Your callback receives the actual DOM element and the IntersectionObserverEntry
261
-
- **Optional cleanup** - Return a function from your callback to run when the element leaves the viewport or is unmounted
262
-
- **Same options** - Accepts all the same [options](#options) as `useInView` except `onChange`
261
+
- **Optional cleanup** - Return a function from your callback to run when the element leaves the viewport
262
+
- **Similar options** - Accepts all the same [options](#options) as `useInView` except `onChange` and `initialInView`
263
+
264
+
The `trigger` option allows to listen for the element entering the viewport or leaving the viewport. The default is `enter`.
/** The IntersectionObserver interface's read-only `root` property identifies the Element or Document whose bounds are treated as the bounding box of the viewport for the element which is the observer's target. If the `root` is null, then the bounds of the actual document viewport are used.*/
25
25
root?: Element|Document|null;
26
26
/** Margin around the root. Can have values similar to the CSS margin property, e.g. `10px 20px 30px 40px` (top, right, bottom, left). */
/** Set the initial value of the `inView` boolean. This can be used if you expect the element to be in the viewport to start with, and you want to trigger something when it leaves. */
35
-
initialInView?: boolean;
36
34
/** IntersectionObserver v2 - Track the actual visibility of the element */
37
35
trackVisibility?: boolean;
38
36
/** IntersectionObserver v2 - Set a minimum delay between notifications */
/** Set the initial value of the `inView` boolean. This can be used if you expect the element to be in the viewport to start with, and you want to trigger something when it leaves. */
0 commit comments