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

210
Views
JavaScript function doesnt execute all of the code in the function

I have a function that makes a PUT request to a server, then after its comeplete. It is supposed to run another piece of code, but it never executes.

  const createNewWatchlist = async () => {
    try {
      const res = await axios({
        url: `http://localhost:5000/api/users/${session?.id}/addwatchlist`,
        method: "PUT",
        data: {
          watchlistName: watchlistName,
          coins: {
            coin: {
              coinID: coinID,
            },
          },
        },
      });
      setPopUp(true);  // Code here & down does not execute
      console.log(popUp);
      console.log(`${watchlistName} created!`);
    } catch (error) {
      console.log(error);
    }
  };

I have a similar function that does work:

  const addCoinToWatchlist = async () => {
    try {
      const res = await axios({
        url: `http://localhost:5000/api/users/${session?.id}/addcointowatchlist`,
        method: "PUT",
        data: {
          watchlistName: selectWatchlist,
          coinID: coinID,
        },
      });
      setSuccessMessage(true);
      console.log(successMessage);
    } catch (error) {
      console.log(error);
    }
  };

Whats the reason the first function only partially works?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to compare executions of that two functions, maybe you execute without await or without .then(...).

about 4 years ago · Juan Pablo Isaza Report
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!