refactor(typesContext.tsx): remove unnecessary retry logic and interval for fetching types
fix(typesContext.tsx): fix issue where component was not unmounting properly and causing memory leaks
This commit is contained in:
parent
f22768c2bc
commit
ea105ee7af
1 changed files with 1 additions and 15 deletions
|
|
@ -38,11 +38,6 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
||||||
const { setLoading } = useContext(alertContext);
|
const { setLoading } = useContext(alertContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let delay = 1000; // Start delay of 1 second
|
|
||||||
let intervalId = null;
|
|
||||||
let retryCount = 0; // Count of retry attempts
|
|
||||||
const maxRetryCount = 5; // Max retry attempts
|
|
||||||
|
|
||||||
// We will keep a flag to handle the case where the component is unmounted before the API call resolves.
|
// We will keep a flag to handle the case where the component is unmounted before the API call resolves.
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
|
|
||||||
|
|
@ -85,22 +80,13 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Clear the interval if successful.
|
|
||||||
clearInterval(intervalId);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("An error has occurred while fetching types.");
|
console.error("An error has occurred while fetching types.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the initial interval.
|
// Start the initial interval.
|
||||||
intervalId = setInterval(getTypes, delay);
|
getTypes();
|
||||||
|
|
||||||
return () => {
|
|
||||||
// This will clear the interval when the component unmounts, or when the dependencies of the useEffect hook change.
|
|
||||||
clearInterval(intervalId);
|
|
||||||
// Indicate that the component has been unmounted.
|
|
||||||
isMounted = false;
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function deleteNode(idx: string) {
|
function deleteNode(idx: string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue