Skip to content

Commit a269340

Browse files
committed
refactor: optimize setTimeout
1 parent c406e68 commit a269340

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/core/createQuery.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ const createQuery = <R, P extends unknown[]>(
9292
let timerId: number;
9393

9494
if (loadingDelay) {
95-
timerId = setTimeout(() => {
96-
setState({
97-
loading: true,
98-
});
99-
}, loadingDelay);
95+
timerId = setTimeout(setState, loadingDelay, {
96+
loading: true,
97+
});
10098
}
10199

102100
return () => timerId && clearTimeout(timerId);
@@ -110,9 +108,7 @@ const createQuery = <R, P extends unknown[]>(
110108
pollingHiddenFlag.value = true;
111109
return;
112110
}
113-
timerId = setTimeout(() => {
114-
pollingFunc();
115-
}, pollingInterval);
111+
timerId = setTimeout(pollingFunc, pollingInterval);
116112
}
117113

118114
return () => timerId && clearTimeout(timerId);

0 commit comments

Comments
 (0)