Skip to content

Commit 3b99428

Browse files
committed
Fix useTimeout bug
1 parent 42c7ce6 commit 3b99428

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,20 +1508,20 @@ export function useThrottle(value, interval = 500) {
15081508
}
15091509

15101510
export function useTimeout(cb, ms) {
1511-
const intervalRef = React.useRef(null);
1511+
const id = React.useRef(null);
15121512
const onTimeout = React.useEffectEvent(cb);
15131513

1514-
const handleClearInterval = () => {
1515-
window.clearInterval(intervalRef.current);
1514+
const handleClearTimeout = () => {
1515+
window.clearTimeout(id.current);
15161516
};
15171517

15181518
React.useEffect(() => {
1519-
intervalRef.current = window.setTimeout(onTimeout, ms);
1519+
id.current = window.setTimeout(onTimeout, ms);
15201520

1521-
return handleClearInterval;
1521+
return handleClearTimeout;
15221522
}, [ms]);
15231523

1524-
return handleClearInterval;
1524+
return handleClearTimeout;
15251525
}
15261526

15271527
export function useToggle(initialValue) {

0 commit comments

Comments
 (0)