We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 509f32e commit 7f5b54bCopy full SHA for 7f5b54b
1 file changed
src/whenIdle.tsx
@@ -10,30 +10,20 @@ function HydrateOnIdle({ children, ...rest }: Props) {
10
React.useEffect(() => {
11
if (hydrated) return;
12
13
- const cleanupFns: VoidFunction[] = [];
14
-
15
- function cleanup() {
16
- for (let i = 0; i < cleanupFns.length; i++) {
17
- cleanupFns[i]();
18
- }
19
20
21
// @ts-ignore
22
if (requestIdleCallback) {
23
24
const idleCallbackId = requestIdleCallback(hydrate, { timeout: 500 });
25
- cleanupFns.push(() => {
+ return () => {
26
27
cancelIdleCallback(idleCallbackId);
28
- });
+ };
29
} else {
30
const id = setTimeout(hydrate, 2000);
31
32
clearTimeout(id);
33
34
}
35
36
- return cleanup;
37
}, [hydrated, hydrate]);
38
39
if (hydrated) {
0 commit comments