@restart/hooks
Advanced tools
Comparing version 0.4.15 to 0.4.16
@@ -8,2 +8,3 @@ "use strict"; | ||
var _useEventCallback = _interopRequireDefault(require("./useEventCallback")); | ||
var _useWillUnmount = _interopRequireDefault(require("./useWillUnmount")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -38,2 +39,4 @@ /** | ||
const lastArgsRef = (0, _react.useRef)(null); | ||
// Use any to bypass type issue with setTimeout. | ||
const timerRef = (0, _react.useRef)(0); | ||
const handleCallback = (0, _useEventCallback.default)(fn); | ||
@@ -49,2 +52,6 @@ const { | ||
const timeout = (0, _useTimeout.default)(); | ||
(0, _useWillUnmount.default)(() => { | ||
clearTimeout(timerRef.current); | ||
isTimerSetRef.current = false; | ||
}); | ||
return (0, _react.useMemo)(() => { | ||
@@ -119,3 +126,3 @@ const hasMaxWait = !!maxWait; | ||
isTimerSetRef.current = true; | ||
setTimeout(timerExpired, wait); | ||
timerRef.current = setTimeout(timerExpired, wait); | ||
return invokeFunc(lastCallTimeRef.current); | ||
@@ -126,3 +133,3 @@ } | ||
isTimerSetRef.current = true; | ||
setTimeout(timerExpired, wait); | ||
timerRef.current = setTimeout(timerExpired, wait); | ||
} | ||
@@ -129,0 +136,0 @@ return returnValueRef.current; |
import { useMemo, useRef } from 'react'; | ||
import useTimeout from './useTimeout'; | ||
import useEventCallback from './useEventCallback'; | ||
import useWillUnmount from './useWillUnmount'; | ||
@@ -33,2 +34,4 @@ /** | ||
const lastArgsRef = useRef(null); | ||
// Use any to bypass type issue with setTimeout. | ||
const timerRef = useRef(0); | ||
const handleCallback = useEventCallback(fn); | ||
@@ -44,2 +47,6 @@ const { | ||
const timeout = useTimeout(); | ||
useWillUnmount(() => { | ||
clearTimeout(timerRef.current); | ||
isTimerSetRef.current = false; | ||
}); | ||
return useMemo(() => { | ||
@@ -114,3 +121,3 @@ const hasMaxWait = !!maxWait; | ||
isTimerSetRef.current = true; | ||
setTimeout(timerExpired, wait); | ||
timerRef.current = setTimeout(timerExpired, wait); | ||
return invokeFunc(lastCallTimeRef.current); | ||
@@ -121,3 +128,3 @@ } | ||
isTimerSetRef.current = true; | ||
setTimeout(timerExpired, wait); | ||
timerRef.current = setTimeout(timerExpired, wait); | ||
} | ||
@@ -124,0 +131,0 @@ return returnValueRef.current; |
{ | ||
"name": "@restart/hooks", | ||
"version": "0.4.15", | ||
"version": "0.4.16", | ||
"main": "cjs/index.js", | ||
@@ -5,0 +5,0 @@ "types": "cjs/index.d.ts", |
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
197088
5482