useRafFn

A React Hook that run a function only once on the next frame using requestAnimationFrame.

Demo

Try to open DevTools to see the console log.

Source

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const rafFn = useRafFn(fn, autoClean)

Fn

A funtion that need to be run on the next frame.

AutoClean

A boolean that will clean the raf when the component unmounts.

Returns

A function that will run the fn on the next frame.