PromoCursed/node_modules/antd/lib/slider/useRafLock.js

29 lines
884 B
JavaScript
Raw Normal View History

2024-08-20 23:25:37 +04:00
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useRafLock;
var React = _interopRequireWildcard(require("react"));
var _raf = _interopRequireDefault(require("rc-util/lib/raf"));
function useRafLock() {
const [state, setState] = React.useState(false);
const rafRef = React.useRef();
const cleanup = () => {
_raf.default.cancel(rafRef.current);
};
const setDelayState = nextState => {
cleanup();
if (nextState) {
setState(nextState);
} else {
rafRef.current = (0, _raf.default)(() => {
setState(nextState);
});
}
};
React.useEffect(() => cleanup, []);
return [state, setDelayState];
}