Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-debounce

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-debounce - npm Package Compare versions

Comparing version 5.2.0 to 5.2.1

7

CHANGELOG.md

@@ -0,1 +1,6 @@

## 5.2.1
- prevent having ininite setTimeout setup when component gets unmounted https://github.com/xnimorz/use-debounce/issues/97
- function type works correctly with `useDebounce` now. https://github.com/xnimorz/use-debounce/pull/95 Thanks to [@csu-feizao](https://github.com/csu-feizao)
## 5.2.0

@@ -90,3 +95,3 @@

```js
const [value, fn] = useDebouncedCallback(/*...*/);
const [value, fn] = useDebounce(/*...*/);
/**

@@ -93,0 +98,0 @@ * value is just a value without changes

@@ -6,6 +6,14 @@ import { useCallback, useEffect, useRef, useState } from 'react';

}
function adjustFunctionValueOfSetState(value) {
return typeof value === 'function' ? function () { return value; } : value;
}
function useStateIgnoreCallback(initialState) {
var _a = useState(adjustFunctionValueOfSetState(initialState)), state = _a[0], setState = _a[1];
var setStateIgnoreCallback = useCallback(function (value) { return setState(adjustFunctionValueOfSetState(value)); }, []);
return [state, setStateIgnoreCallback];
}
export default function useDebounce(value, delay, options) {
var eq = (options && options.equalityFn) || valueEquality;
var _a = useState(value), state = _a[0], dispatch = _a[1];
var debounced = useDebouncedCallback(useCallback(function (value) { return dispatch(value); }, []), delay, options);
var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
var debounced = useDebouncedCallback(useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
var previousValue = useRef(value);

@@ -12,0 +20,0 @@ useEffect(function () {

@@ -126,2 +126,6 @@ import { useRef, useCallback, useEffect, useMemo } from 'react';

}
// https://github.com/xnimorz/use-debounce/issues/97
if (!mounted.current) {
return;
}
// Remaining wait calculation

@@ -128,0 +132,0 @@ var timeSinceLastCall = time - lastCallTime.current;

@@ -8,6 +8,14 @@ "use strict";

}
function adjustFunctionValueOfSetState(value) {
return typeof value === 'function' ? function () { return value; } : value;
}
function useStateIgnoreCallback(initialState) {
var _a = react_1.useState(adjustFunctionValueOfSetState(initialState)), state = _a[0], setState = _a[1];
var setStateIgnoreCallback = react_1.useCallback(function (value) { return setState(adjustFunctionValueOfSetState(value)); }, []);
return [state, setStateIgnoreCallback];
}
function useDebounce(value, delay, options) {
var eq = (options && options.equalityFn) || valueEquality;
var _a = react_1.useState(value), state = _a[0], dispatch = _a[1];
var debounced = useDebouncedCallback_1.default(react_1.useCallback(function (value) { return dispatch(value); }, []), delay, options);
var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
var debounced = useDebouncedCallback_1.default(react_1.useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
var previousValue = react_1.useRef(value);

@@ -14,0 +22,0 @@ react_1.useEffect(function () {

@@ -128,2 +128,6 @@ "use strict";

}
// https://github.com/xnimorz/use-debounce/issues/97
if (!mounted.current) {
return;
}
// Remaining wait calculation

@@ -130,0 +134,0 @@ var timeSinceLastCall = time - lastCallTime.current;

8

package.json
{
"name": "use-debounce",
"version": "5.2.0",
"version": "5.2.1",
"description": "Debounce hook for react",

@@ -17,8 +17,8 @@ "main": "lib/index.js",

"scripts": {
"size": "yarn build && size-limit",
"size": "yarn build:es && size-limit",
"test": "yarn jest && eslint \"src/**.ts\"",
"build": "rm -rf ./lib/* ./esm/* && yarn build:cjs && yarn build:es",
"build": "rm -rf ./lib/* ./esm/* && yarn test && yarn size && yarn build:cjs && yarn build:es",
"build:cjs": "tsc",
"build:es": "tsc -m esNext --outDir esm",
"prepublishOnly": "npm run build"
"prepublishOnly": "yarn build"
},

@@ -25,0 +25,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc