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?
Try to compare executions of that two functions, maybe you execute without await or without .then(...).