Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
¿Cómo puedo abortar la solicitud de axios tan pronto como la recibí?

actualmente, estoy usando axios e intento obtener la solicitud y establecer datos y luego anular la solicitud usando useState con intervalo.

sin embargo, parece que la solicitud no mantiene la solicitud de cancelación tan pronto como se recibe la solicitud.

¡Quiero saber si es posible abortar la solicitud!

mi código es así.

 const controller = new AbortController(); const CancelToken = axios.CancelToken; const source = CancelToken.source(); const getAPI = useCallback(async () => { await axios .get(convert.GET_API_URL, { headers: convert.Header, cancelToken: source.token, signal: controller.signal, }) .then(response => { setAPI_DATA(response.data); setSpinner(false); source.cancel(); controller.abort(); }) .catch(error => { setSpinner(false); }); }, [API_DATA, convert, spinner]); useInterval( () => { getAPI(); }, apiStart ? convert?.API_Read_Speed : null );

useInterval

 import { useEffect } from "react"; import { useRef } from "react"; const useInterval = (callback, delay) => { const savedCallback = useRef(callback); useEffect(() => { savedCallback.current = callback; }, [callback]); useEffect(() => { const tick = () => { savedCallback.current(); }; if (delay !== null) { const id = setInterval(tick, delay); return () => clearInterval(id); } }, [delay]); }; export default useInterval;

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!