0

I want to call a function at the end of request (when I get the response) with Superagent.

request.post('/TextUpload')
.send({title:this.state.title1})
.end( function(res){
   console.log(res);
   this.myFunction();
})

But I get the error : this is null or undefined.

MyFunction() is declared and binded in the constructor. I cannot write the code of the function directly in the callback because I do this.props.refresh(true); (it sends Data to the parent)

Pol Grisart
  • 179
  • 4
  • 13

1 Answers1

1

I get the error : this is null or undefined.?

This should work.Use arrow function to get the lexical scope binding

.end((res)=>{
   console.log(res);
   this.myFunction();
})
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53