UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

25 lines (24 loc) 888 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useRafEffect = void 0; /* eslint-disable @typescript-eslint/no-explicit-any */ var react_1 = require("react"); var __1 = require(".."); /** * 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`. */ function useRafEffect(callback, deps) { var _a = (0, __1.useRafCallback)(callback), rafCallback = _a[0], cancelRaf = _a[1]; // eslint-disable-next-line react-hooks/exhaustive-deps (0, react_1.useEffect)(function () { rafCallback(); return cancelRaf; }, // eslint-disable-next-line react-hooks/exhaustive-deps deps); } exports.useRafEffect = useRafEffect;