use-debounce
Advanced tools
Comparing version 0.0.8 to 0.0.9-beta
@@ -6,25 +6,15 @@ 'use strict'; | ||
}); | ||
exports.useDebounce = undefined; | ||
exports.useDebouncedCallback = exports.useDebounce = undefined; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _cache = require('./cache'); | ||
var _react = require('react'); | ||
var _cache2 = _interopRequireDefault(_cache); | ||
var useDebounce = exports.useDebounce = function useDebounce(value, delay) { | ||
var _useState = (0, _react.useState)(value), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
debouncedValue = _useState2[0], | ||
setDebouncedValue = _useState2[1]; | ||
var _callback = require('./callback'); | ||
(0, _react.useEffect)(function () { | ||
var handler = setTimeout(function () { | ||
setDebouncedValue(value); | ||
}, delay); | ||
var _callback2 = _interopRequireDefault(_callback); | ||
return function () { | ||
clearTimeout(handler); | ||
}; | ||
}, [value, delay]); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return debouncedValue; | ||
}; | ||
exports.useDebounce = _cache2.default; | ||
exports.useDebouncedCallback = _callback2.default; |
{ | ||
"name": "use-debounce", | ||
"version": "0.0.8", | ||
"version": "0.0.9-beta", | ||
"description": "Debounce hook for react", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,17 +0,4 @@ | ||
import { useState, useEffect } from 'react'; | ||
import useDebounce from './cache'; | ||
import useDebouncedCallback from './callback'; | ||
export const useDebounce = (value, delay) => { | ||
const [debouncedValue, setDebouncedValue] = useState(value); | ||
useEffect(() => { | ||
const handler = setTimeout(() => { | ||
setDebouncedValue(value); | ||
}, delay); | ||
return () => { | ||
clearTimeout(handler); | ||
}; | ||
}, [value, delay]); | ||
return debouncedValue; | ||
}; | ||
export { useDebounce, useDebouncedCallback }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198160
17
154