From: Daniel Karbach Date: Tue, 12 Apr 2022 22:12:48 +0000 (+0200) Subject: properly abort requests X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=d1e6672bca5fb89428e3028227bb989dbc381042;p=alttp.git properly abort requests --- 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(() => {