@dh-react-hooks/use-raf

react hooks for requestAnimationFrame

Usage no npm install needed!

<script type="module">
  import dhReactHooksUseRaf from 'https://cdn.skypack.dev/@dh-react-hooks/use-raf';
</script>

README

@dh-react-hooks/use-raf

NPM version codecov

react hooks for handling requestAnimationFrame

Installation

npm i @dh-react-hooks/use-raf

Arguments

props type required default description
disable boolean false false disable to call requestAnimationFrame at the first time
duration number false undefined duration time to call requestAnimationFrame in milliseconed. it not specify, callback will loop infinitely
callback function true undefined callback function to requestAnimationFrame

Way to Ride

  • Common jS
const useRaf = require('@dh-react-hooks/use-raf')

  const { isActive, start, stop } = useRaf.default({
    disable,
    duration,
    callback
  })
  • ESM
import useRaf from '@dh-react-hooks/use-raf'
  
  const { isActive, start, stop } = useRaf({
    disable,
    duration,
    callback
  })