1 useEffect(() => {
2 const abortController = new AbortController();
3
4 const fetchData = async () => {
5 dispatch(requestStarted());
6
7 try {
8 fetch(url, { signal: abortController.signal });
9
10 // code omitted for brevity
11
12 dispatch(requestSuccessful({ data }));
13 } catch (e) {
14 dispatch(requestFailed({ error: e.message }));
15 }
16 };
17
18 fetchData();
19
20 return () => {
21 abortController.abort();
22 };
23 }, [url]);
24