Skip to content

Commit 4254542

Browse files
dlsxjzldkimyouknow
andauthored
fix(useTimeout): remove window prefix from setTimeout and clearTimeout for platform independence (#333)
Co-authored-by: 김윤호 yunho <kimyouknow@naver.com>
1 parent e5f6cac commit 4254542

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

.changeset/twelve-coats-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-simplikit': patch
3+
---
4+
5+
remove window prefix from setTimeout and clearTimeout for platform-independent

packages/core/src/hooks/useTimeout/useTimeout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { usePreservedCallback } from '../usePreservedCallback/index.ts';
55
/**
66
* @description
77
* `useTimeout` is a React hook that executes a callback function after a specified delay.
8-
* It manages `window.setTimeout` in accordance with the React lifecycle, ensuring cleanup on unmount or when dependencies change.
8+
* It manages `setTimeout` in accordance with the React lifecycle, ensuring cleanup on unmount or when dependencies change.
99
*
1010
* @param {() => void} callback - The function to be executed after the delay.
1111
* @param {number} [delay=0] - The time in milliseconds to wait before executing the callback.
@@ -34,7 +34,7 @@ export function useTimeout(callback: () => void, delay = 0) {
3434
const preservedCallback = usePreservedCallback(callback);
3535

3636
useEffect(() => {
37-
const timeoutId = window.setTimeout(preservedCallback, delay);
38-
return () => window.clearTimeout(timeoutId);
37+
const timeoutId = setTimeout(preservedCallback, delay);
38+
return () => clearTimeout(timeoutId);
3939
}, [delay, preservedCallback]);
4040
}

0 commit comments

Comments
 (0)