Skip to main content

How can I return the response of the Axios Post in React?

I have a little problem.

I have a post function in ReactJS (totally working). I wanna have the response of it outside this function, right where I called it. How can I do that?

async function confereInicial(idAluno,idDisciplina){

  return await Axios.post("http://localhost:3001/api/check",{
      idAluno: idAluno,
      idDisciplina: idDisciplina}).then((response)=> {
  });

}

//please ignore the way I call and read my function. it's confusing but I just wanna console.log the data outside my function. ignore the map etc

  return (
    <div>

              {
              
              dados.state.nodesPadrao.map(p => {
                confereInicial(1,p.id).then(data => console.log(data)); //how should I do that?




app.post("/api/check",(req,res) => {

    const idAluno = req.body.idAluno;
    const idDisciplina = req.body.idDisciplina;

    const sqlSelect = "SELECT * FROM `disciplinas_feitas` WHERE id_aluno = ? AND id_disciplina = ?;"
    db.query(sqlSelect,[idAluno,idDisciplina],(err,result) => {
        res.send(result);
    });

});

may someone please help me?

Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

Comments