Skip to content

Commit 2f65d87

Browse files
jstckithebuilder
authored andcommitted
Add note about constant threshold array (#251)
Fixes #248
1 parent 7961292 commit 2f65d87

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ argument for the hooks.
151151
| **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. |
152152
| **triggerOnce** | boolean | false | false | Only trigger this method once |
153153

154+
> ⚠️ When passing an array to `threshold`, store the array in a constant to avoid
155+
> the component re-rendering too often. For example:
156+
157+
```js
158+
const THRESHOLD = [0.25, 0.5, 0.75]; // Store multiple thresholds in a constant
159+
const MyComponent = () => {
160+
const [ref, inView, entry] = useInView({threshold: THRESHOLD});
161+
return <div ref={ref}>Triggered at intersection ratio {entry.intersectionRatio}</div>;
162+
}
163+
```
164+
154165
### InView Props
155166

156167
The **`<InView />`** component also accepts the following props:

0 commit comments

Comments
 (0)