React Hook which tells you when you've scrolled to bottom
React Hook which tells you when you've scrolled to bottom
Uses IntersectionObserver so make sure you can support it.
npm install --save use-scroll-to-bottom
The hook returns a tuple of two things:
import React from 'react';
import {useScrollToBottom} from 'use-scroll-to-bottom'
export default function MyComponent() {
// isBottom will be true when bottom is reached
// add setBottomRef to the last element in your scrolling container
const [setBottomRef, isBottom] = useScrollToBottom();
return (
<div className="simple-container">
<div className="big-element">
{isBottom && "Bottom reached"}
</div>
<div ref={setBottomRef}>Bottom</div>
</div>
)
}
MIT © tudorgergely