Size
0.76 kb
useInView
Track the visibility of an element.
Installation
Usage
Track the visibility of an element:
Set a default value until the target is observed:
Customize the intersection observer:
Observe once:
API Reference
UseInViewOptions
Options for the useInView hook.
Prop | Type | Default |
---|---|---|
onChange? | ((inView: boolean) => void) | - |
trackState? | boolean | true |
autoObserve? | boolean | true |
threshold? | number | number[] | - |
rootMargin? | string | - |
root? | Element | Document | null | - |
UseInViewReturn
Return value for the useInView hook.
Prop | Type | Default |
---|---|---|
inView | boolean | undefined | - |
target | Element | null | - |
ref | Function | - |
unobserve | () => void | - |
observe | () => void | - |