@shopify/react-hooks
Advanced tools
Comparing version 1.11.0 to 1.11.1
@@ -10,4 +10,11 @@ # Changelog | ||
## [1.20.0] - 2020-08-18 | ||
## [1.11.1] - 2020-08-19 | ||
### Fixed | ||
- `useDelayedCallback` now uses `useRef` instead of `useState` in to avoid unnecessary re-render ([#1600](https://github.com/Shopify/quilt/pull/1600)) | ||
- Improved test case for `useDelayedCallback` ([#1601](https://github.com/Shopify/quilt/pull/1601)) | ||
## [1.11.0] - 2020-08-18 | ||
### Added | ||
@@ -14,0 +21,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var react_1 = require("react"); | ||
function useDelayedCallback(callback, delay) { | ||
var _a = tslib_1.__read(react_1.useState(), 2), timeoutId = _a[0], setTimeoutId = _a[1]; | ||
var timeoutRef = react_1.useRef(); | ||
react_1.useEffect(function () { | ||
return function () { | ||
if (timeoutId != null) { | ||
clearTimeout(timeoutId); | ||
if (timeoutRef.current != null) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
function callbackWithDelay() { | ||
var callbackId = setTimeout(function () { | ||
var timeoutId = setTimeout(function () { | ||
callback(); | ||
setTimeoutId(undefined); | ||
timeoutRef.current = undefined; | ||
}, delay); | ||
setTimeoutId(callbackId); | ||
timeoutRef.current = timeoutId; | ||
} | ||
@@ -22,0 +20,0 @@ return callbackWithDelay; |
{ | ||
"name": "@shopify/react-hooks", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A collection of primitive React hooks", |
Sorry, the diff of this file is not supported yet
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
24979
267