Skip to content

Commit 1fe8907

Browse files
authored
Update Recipes.md
1 parent e889d90 commit 1fe8907

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/Recipes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { useInView } from 'react-intersection-observer'
3232
const LazyImage = ({ width, height, src, ...rest }) => {
3333
const [ref, inView] = useInView({
3434
triggerOnce: true,
35-
threshold: 0,
35+
rootMargin: 200px 0px,
3636
})
3737

3838
return (
@@ -95,6 +95,7 @@ fire an event on your tracking service.
9595
- Set `triggerOnce`, to only trigger an event the first time the element enters the viewport.
9696
- Set `threshold`, to control how much of the element should visible before
9797
firing the event.
98+
- Instead of `threshold`, you can use `rootMargin` to have a fixed amount be visible before triggering. Use a negative margin value, like `-100px 0`, to have it go inwards. You can also use a percentage value, instead of pixels.
9899

99100
```jsx
100101
import React, { useEffect } from 'react'

0 commit comments

Comments
 (0)