Skip to content

Commit

Permalink
fix: added clear-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Apr 10, 2024
1 parent 67b23e1 commit bce4ffa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/landing-page/productions-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ export const ProductionsList = () => {
// TODO extract to separate hook file
useEffect(() => {
let aborted = false;
let timeout: number | null = null;

if (reloadProductionList) {
setLoading(true);
API.listProductions()
.then((result) => {
if (aborted) return;
if (aborted) {
if (timeout !== null) {
window.clearTimeout(timeout);
}
return;
}

setProductions(
result
Expand All @@ -71,13 +77,13 @@ export const ProductionsList = () => {
dispatch({
type: "PRODUCTION_LIST_FETCHED",
});
window.setTimeout(() => {
timeout = window.setTimeout(() => {
setLoading(false);
}, 2500);
})
.catch(() => {
// TODO handle error/retry
window.setTimeout(() => {
timeout = window.setTimeout(() => {
setLoading(false);
}, 2500);
});
Expand Down

0 comments on commit bce4ffa

Please sign in to comment.