PromoCursed/node_modules/antd/lib/form/hooks/useDebounce.js
2024-08-20 23:25:37 +04:00

20 lines
569 B
JavaScript

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useDebounce;
var React = _interopRequireWildcard(require("react"));
function useDebounce(value) {
const [cacheValue, setCacheValue] = React.useState(value);
React.useEffect(() => {
const timeout = setTimeout(() => {
setCacheValue(value);
}, value.length ? 0 : 10);
return () => {
clearTimeout(timeout);
};
}, [value]);
return cacheValue;
}