@react-hookz/web
Version:
React hooks done right, for browser and SSR.
19 lines (18 loc) • 629 B
JavaScript
import { useEffect } from 'react';
import { useRafCallback } from '../useRafCallback/index.js';
/**
* Like `React.useEffect`, but state is only updated within animation frame.
*
* @param callback Callback like for `useEffect`, but without ability to return
* a cleanup function.
* @param deps Dependencies list that will be passed to underlying `useEffect`.
*/
export function useRafEffect(callback, deps) {
const [rafCallback, cancelRaf] = useRafCallback(callback);
useEffect(() => {
rafCallback();
return cancelRaf;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
deps);
}