React animation hook that forces component to re-render on each requestAnimationFrame
,
returns percentage of time elapsed.
import {useRaf} from 'react-use';
const Demo = () => {
const elapsed = useRaf(5000, 1000);
return (
<div>
Elapsed: {elapsed}
</div>
);
};
useRaf(ms?: number, delay?: number): number;
ms
— milliseconds for how long to keep re-rendering component, defaults to1e12
.delay
— delay in milliseconds after which to start re-rendering component, defaults to0
.