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

158
Views
axios call dont return a promise

Explanation: in my hook I receive this get exercises from a page that I have, it executes well in the function "callEndpoint ", but at the moment of executing the await axiosCall.call; it does not return me a promise, it returns me a normal function, therefore I cannot solve the promise.

How can I do so that the hook returns me a promise? what is the error?

const useFetchAndLoad = () => {
  const [loading, setLoading] = useState(false);
  let controller = new AbortController();

  const callEndpoint = async (axiosCall) => {
    if (axiosCall.controller) controller = axiosCall.controller;
    setLoading(true);
    let result = {};
    try {
      result = await axiosCall.call;
    } catch (err) {
      setLoading(false);
      throw err;
    }
    setLoading(false);
    return result;
  };

  const cancelEndpoint = () => {
    setLoading(false);
    if (controller) {
      controller.abort();
    }
  };

  useEffect(() => {
    return () => {
      cancelEndpoint();
    };
  }, []);

  return { loading, callEndpoint };
};

And I send this:

const getExercises = () => {
  const controller = loadAbortAxios();
  return {
    call: axios.request(options.GET_EXCERSICES, { signal: controller.signal }),
    controller: new AbortController(),
  };


};
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!