Skip to content
Discussion options

You must be logged in to vote

You fetchQuestion function is mixing async/await and .then promise chaining.

This should fetch your data and then wait to respond until it is received. Your current code will return before the .then is called.

async function fetchQuestion(qid){
  try {
    const response = await axios.get("http://localhost:9000/api/questions/"+qid);
    const question = response.data;
    return question;
  } catch(err) {
    console.log("Error while fetching questions", err);
    return null;
  }
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@uinstinct
Comment options

@jamesmosier
Comment options

@uinstinct
Comment options

Answer selected by uinstinct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants