-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rootMargin doesn't work when root default to null #32
Comments
I may implemented a better version of this hookEasier to use, less properties required, same ability, here is a simple usage: export default function App() {
const [list, setList] = useState([...Array(11).keys()])
const { containerRef, isLoading } = useInfiniteScroll({
async onLoadMore() {
const res = await fetchList(list.slice(-1)[0])
setList(list.concat(res))
},
})
return (
<div className="App">
<List ref={containerRef}>
{list.map((n) => (
<Item key={n}>{n}</Item>
))}
{isLoading && <Loading>Loading ...</Loading>}
</List>
</div>
) Use
|
Update the next day:I made it to become another independent library https://github.com/iamyoki/infinite-scroll-hook |
See this example in codesandbox
https://codesandbox.io/s/try-react-infinite-scroll-hook-4ekfj1?file=/src/App.jsx:1374-1384
This is a common pitfall when using
rootMargin
withoutroot
specifiedLittle rules of
Interception Observer API
:root
default to viewport while the viewport doesn't have any margin, so setrootMargin
to any value will always fallback to0px
.The text was updated successfully, but these errors were encountered: