UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

21 lines (20 loc) 743 B
/* eslint-disable @typescript-eslint/no-explicit-any */ import { useEffect } from 'react'; import { useRafCallback } from '..'; /** * 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) { var _a = useRafCallback(callback), rafCallback = _a[0], cancelRaf = _a[1]; // eslint-disable-next-line react-hooks/exhaustive-deps useEffect(function () { rafCallback(); return cancelRaf; }, // eslint-disable-next-line react-hooks/exhaustive-deps deps); }