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
|**root**|`Element`| document | false | 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. |
148
-
|**rootMargin**|`string`| '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
149
-
|**threshold**|`number`\|`number[]`| 0 | false | 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. |
150
-
|**trackVisibility** 🧪 |`boolean`| false | false | A boolean indicating whether this IntersectionObserver will track visibility changes on the target. |
151
-
|**delay** 🧪 |`number`| undefined | false | A number indicating the minimum delay in milliseconds between notifications from this observer for a given target. This must be set to at least `100` if `trackVisibility` is `true`. |
152
-
|**skip**|`boolean`| false | false | Skip creating the IntersectionObserver. You can use this to enable and disable the observer as needed. If `skip` is set while `inView`, the current state will still be kept. |
153
-
|**triggerOnce**|`boolean`| false | false | Only trigger the observer once. |
154
-
|**initialInView**|`boolean`| false | false | 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. |
144
+
Provide these as the options argument in the `useInView` hook or as props on the
145
+
**`<InView />`** component.
146
+
147
+
| Name | Type | Default | Required | Description |
|**root**|`Element`| document | false | 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. |
150
+
|**rootMargin**|`string`| '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
151
+
|**threshold**|`number`\|`number[]`| 0 | false | 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
+
|**trackVisibility** 🧪 |`boolean`| false | false | A boolean indicating whether this IntersectionObserver will track visibility changes on the target. |
153
+
|**delay** 🧪 |`number`| undefined | false | A number indicating the minimum delay in milliseconds between notifications from this observer for a given target. This must be set to at least `100` if `trackVisibility` is `true`. |
154
+
|**skip**|`boolean`| false | false | Skip creating the IntersectionObserver. You can use this to enable and disable the observer as needed. If `skip` is set while `inView`, the current state will still be kept. |
155
+
|**triggerOnce**|`boolean`| false | false | Only trigger the observer once. |
156
+
|**initialInView**|`boolean`| false | false | 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. |
157
+
|**fallbackInView**|`boolean`| undefined | false | If the `IntersectionObserver` API isn't available in the client, the default behavior is to throw an Error. You can set a specific fallback behavior, and the `inView` value will be set to this instead of failing. To set a global default, you can set it with the `defaultFallbackInView()`|
155
158
156
159
### InView Props
157
160
@@ -307,6 +310,45 @@ With
307
310
all major browsers now support Intersection Observers natively. Add the
308
311
polyfill, so it doesn't break on older versions of iOS and IE11.
309
312
313
+
### Unsupported fallback
314
+
315
+
If the client doesn't have support for the `IntersectionObserver`, then the
316
+
default behavior is to throw an error. This will crash the React application,
317
+
unless you capture it with an Error Boundary.
318
+
319
+
If you prefer, you can set a fallback `inView` value to use if the
320
+
`IntersectionObserver` doesn't exist. This will make
321
+
`react-intersection-observer` fail gracefully, but you must ensure your
322
+
application can correctly handle all your observers firing either `true` or
/** 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. */
33
34
initialInView?: boolean;
35
+
/** Fallback to this inView state if the IntersectionObserver is unsupported, and a polyfill wasn't loaded */
36
+
fallbackInView?: boolean;
34
37
/** IntersectionObserver v2 - Track the actual visibility of the element */
35
38
trackVisibility?: boolean;
36
39
/** IntersectionObserver v2 - Set a minimum delay between notifications */
1 commit comments
vercel[bot] commentedon Dec 9, 2021
Successfully deployed to the following URLs: