Add AbortController cleanup to async frontend effects
This commit is contained in:
@@ -23,16 +23,27 @@ export function useSchedule(): UseScheduleReturn {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
setLoading(true);
|
||||
fetchSchedule()
|
||||
setError(null);
|
||||
|
||||
fetchSchedule(controller.signal)
|
||||
.then((data) => {
|
||||
if (controller.signal.aborted) return;
|
||||
setInfo(data);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
if (controller.signal.aborted) return;
|
||||
handleFetchError(err, setError, "Failed to load schedule");
|
||||
})
|
||||
.finally(() => {
|
||||
if (controller.signal.aborted) return;
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
return (): void => {
|
||||
controller.abort();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const saveSchedule = useCallback(async (config: ScheduleConfig): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user