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
Copy file name to clipboardExpand all lines: README.md
+48-63
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,6 @@ to tell you when an element enters or leaves the viewport. Contains both a
12
12
[Hooks](#useinview-hook), [render props](#render-props) and
13
13
[plain children](#plain-children) implementation.
14
14
15
-
16
15
## Features
17
16
18
17
- 🪝 **Hooks or Component API** - With `useInView` it's easier than ever to
@@ -28,6 +27,8 @@ to tell you when an element enters or leaves the viewport. Contains both a
28
27
- 💥 **Tiny bundle** - Around **~1.15kB** for `useInView` and **~1.6kB** for
29
28
`<InView>`
30
29
30
+
[](https://stackblitz.com/github/thebuilder/react-intersection-observer)
31
+
31
32
## Installation
32
33
33
34
Install the package with your package manager of choice:
@@ -57,8 +58,8 @@ Assign the `ref` to the DOM element you want to monitor, and the hook will
|**root**|`Element`|`document`| The Intersection Observer 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. |
140
141
|**rootMargin**|`string`|`'0px'`| Margin around the root. Can have values similar to the CSS margin property, e.g. `"10px 20px 30px 40px"` (top, right, bottom, left). Also supports percentages, to check if an element intersects with the center of the viewport for example "-50% 0% -50% 0%". |
141
142
|**threshold**|`number` or `number[]`|`0`| Number between `0` and `1` indicating the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
@@ -152,7 +153,7 @@ Provide these as the options argument in the `useInView` hook or as props on the
152
153
The **`<InView />`** component also accepts the following props:
|**as**|`IntrinsicElement`|`'div'`| Render the wrapping element as this element. Defaults to `div`. If you want to use a custom component, please use the `useInView` hook or a render prop instead to manage the reference explictly. |
157
158
|**children**|`({ref, inView, entry}) => ReactNode` or `ReactNode`|`undefined`| Children expects a function that receives an object containing the `inView` boolean and a `ref` that should be assigned to the element root. Alternatively pass a plain child, to have the `<InView />` deal with the wrapping element. You will also get the `IntersectionObserverEntry` as `entry`, giving you more details. |
158
159
@@ -199,8 +200,8 @@ few ideas for how you can use it.
199
200
You can wrap multiple `ref` assignments in a single `useCallback`:
| `mockAllIsIntersecting(isIntersecting)` | Set `isIntersecting` on all current Intersection Observer instances. The value of `isIntersecting` should be either a `boolean` or a threshold between 0 and 1. |
250
251
| `mockIsIntersecting(element, isIntersecting)` | Set `isIntersecting` for the Intersection Observer of a specific `element`. The value of `isIntersecting` should be either a `boolean` or a threshold between 0 and 1. |
251
252
| `intersectionMockInstance(element)` | Call the `intersectionMockInstance` method with an element, to get the (mocked) `IntersectionObserver` instance. You can use this to spy on the `observe` and`unobserve` methods. |
@@ -271,11 +272,11 @@ Jest. Otherwise, you'll need to manually setup/reset the mocking in either the
271
272
individual tests, or a [setup file](https://vitest.dev/config/#setupfiles).
0 commit comments