jay-jlm / use-smooth-scroll

React hook which gives a smooth scrolling function.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

use-smooth-scroll

React hook which gives a smooth scrolling function.

Example (Codesandbox)

const Example = () => {
  const ref = React.useRef()
  const scrollTo = useSmoothScroll('x', ref)

  return (
    <>
      <button onClick={() => scrollTo(getRandomScrollTarget(ref.current))}>
        Click me
      </button>
      <Carousel innerRef={ref}>
        {range(100).map(i => (
          <Card key={i} />
        ))}
      </Carousel>
    </>
  )
}

About

React hook which gives a smooth scrolling function.


Languages

Language:JavaScript 100.0%