]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/Tournament.js
properly abort requests
[alttp.git] / resources / js / components / pages / Tournament.js
index 00a19343c11b1c99c59d59937946f6ce85f89b17..061db2208a8a67ba35ddd05ff9fced3afd1323bf 100644 (file)
@@ -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(() => {