From d1e6672bca5fb89428e3028227bb989dbc381042 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 13 Apr 2022 00:12:48 +0200 Subject: [PATCH] properly abort requests --- resources/js/components/pages/Tournament.js | 6 +++++- resources/js/components/pages/User.js | 6 +++++- resources/js/components/protocol/Protocol.js | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/js/components/pages/Tournament.js b/resources/js/components/pages/Tournament.js index 00a1934..061db22 100644 --- a/resources/js/components/pages/Tournament.js +++ b/resources/js/components/pages/Tournament.js @@ -26,9 +26,10 @@ const Tournament = () => { const [tournament, setTournament] = useState(null); useEffect(() => { + const ctrl = new AbortController(); setLoading(true); axios - .get(`/api/tournaments/${id}`) + .get(`/api/tournaments/${id}`, { signal: ctrl.signal }) .then(response => { setError(null); setLoading(false); @@ -40,6 +41,9 @@ const Tournament = () => { setLoading(false); setTournament(null); }); + return () => { + ctrl.abort(); + }; }, [id]); useEffect(() => { diff --git a/resources/js/components/pages/User.js b/resources/js/components/pages/User.js index bb26bfa..3e868ba 100644 --- a/resources/js/components/pages/User.js +++ b/resources/js/components/pages/User.js @@ -18,8 +18,9 @@ const User = () => { useEffect(() => { setLoading(true); + const ctrl = new AbortController(); axios - .get(`/api/users/${id}`) + .get(`/api/users/${id}`, { signal: ctrl.signal }) .then(response => { setError(null); setLoading(false); @@ -31,6 +32,9 @@ const User = () => { setLoading(false); setUser(null); }); + return () => { + ctrl.abort(); + }; }, [id]); useEffect(() => { diff --git a/resources/js/components/protocol/Protocol.js b/resources/js/components/protocol/Protocol.js index 7cd0b75..a2bb930 100644 --- a/resources/js/components/protocol/Protocol.js +++ b/resources/js/components/protocol/Protocol.js @@ -13,11 +13,15 @@ const Protocol = ({ id }) => { const [protocol, setProtocol] = useState([]); useEffect(() => { + const ctrl = new AbortController(); axios - .get(`/api/protocol/${id}`) + .get(`/api/protocol/${id}`, { signal: ctrl.signal }) .then(response => { setProtocol(response.data); }); + return () => { + ctrl.abort(); + }; }, [id]); useEffect(() => { -- 2.39.2