]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/protocol/Protocol.js
properly abort requests
[alttp.git] / resources / js / components / protocol / Protocol.js
index e94cad7bf436667ec1f61c724f299287212523d6..a2bb93060a3fce351938b60588a392d2d63d0a25 100644 (file)
@@ -13,17 +13,20 @@ 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(() => {
                window.Echo.private(`Protocol.${id}`)
                        .listen('ProtocolAdded', e => {
-                               console.log(e);
                                if (e.protocol) {
                                        setProtocol(protocol => [e.protocol, ...protocol]);
                                }