/use-scroll-to-bottom

React Hook which tells you when you've scrolled to bottom

Primary LanguageJavaScript

use-scroll-to-bottom

React Hook which tells you when you've scrolled to bottom

Uses IntersectionObserver so make sure you can support it.

NPM

Install

npm install --save use-scroll-to-bottom

Usage

Check demo and examples

import React from 'react';
import {useScrollToBottom} from 'use-scroll-to-bottom'

export default function MyComponent() {
  // isBottom will be true when bottom is reached
  // add ref to an element right below your scrollable one
  const [ref, isBottom] = useScrollToBottom();

  return (
    <div className="simple-container">
      <div className="big-element">
        {isBottom && "Bottom reached"}
      </div>
      <div ref={ref}>Bottom</div>
    </div>
  )
}

License

MIT © tudorgergely