Skip to content

Commit 75f7aff

Browse files
committed
🐛 Fix invalid react state update in WaitUntil
1 parent b2c2f78 commit 75f7aff

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/components/WaitUntil.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
FC,
33
ReactNode,
4-
useRef,
4+
useEffect,
55
useState
66
} from "react";
77

@@ -22,11 +22,11 @@ const handleTasks = async (tasks: TaskList) => {
2222

2323
export const WaitUntil: FC<{tasks: TaskList, children?: ReactNode, loadingComponent?: ReactNode}> = ({ tasks, children, loadingComponent }) => {
2424
const [loaded, setLoaded] = useState(() => !tasks.length);
25-
const mounted = useRef(false);
2625

27-
if(!mounted.current) handleTasks(tasks).finally(() => setLoaded(true))
26+
useEffect(() => {
27+
handleTasks(tasks).finally(() => setLoaded(true));
28+
// eslint-disable-next-line react-hooks/exhaustive-deps
29+
}, []);
2830

29-
mounted.current = true;
30-
31-
return (loaded ? children : loadingComponent) as JSX.Element;
31+
return loaded ? children : loadingComponent;
3232
}

0 commit comments

Comments
 (0)