Skip to content

Commit 90df622

Browse files
committed
refactor: clean up current code
1 parent b2870a6 commit 90df622

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

site/src/components/Spinner/Spinner.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,31 @@ export const Spinner: FC<SpinnerProps> = ({
9090
// only bails out of redundant state updates if they happen outside of a
9191
// render. Inside a render, if you keep calling a state dispatch, you will
9292
// get an infinite render loop, no matter what the state value is.
93-
const [delayDone, setDelayDone] = useState(safeDelay === 0);
94-
if (delayDone && !loading) {
95-
setDelayDone(false);
93+
const [delayExpired, setDelayExpired] = useState(safeDelay === 0);
94+
if (delayExpired && !loading) {
95+
setDelayExpired(false);
9696
}
97-
if (!delayDone && loading && safeDelay === 0) {
98-
setDelayDone(true);
97+
if (!delayExpired && safeDelay === 0) {
98+
setDelayExpired(true);
9999
}
100100
useEffect(() => {
101101
if (safeDelay === 0) {
102102
return;
103103
}
104104

105105
const delayId = window.setTimeout(() => {
106-
setDelayDone(true);
106+
setDelayExpired(true);
107107
}, safeDelay);
108108
return () => window.clearTimeout(delayId);
109109
}, [safeDelay]);
110110

111111
/**
112112
* @todo Figure out if this conditional logic can ever cause a component to
113-
* lose state. I would hope not, since the children prop is the same in both
114-
* cases, but I need to test this out
113+
* lose state when showSpinner flips from false to true while
114+
* unmountedWhileLoading is false. I would hope not, since the children prop
115+
* is the same in both cases, but I need to test this out
115116
*/
116-
const showSpinner = delayDone && loading;
117+
const showSpinner = loading && delayExpired;
117118
if (!showSpinner) {
118119
return children;
119120
}

0 commit comments

Comments
 (0)