need to refresh page after axios call

Viewed 9488

As the title states, I need to refresh the page after an axios call function, but not before the promise has been received. The page is currently refreshing after the function fires but the promise is not received . What I am trying to do is to submit a blog post to the api, When I add the preventDefault function at the end everything works as it should.

here function:

handleSubmit(event){
    axios.post("https://saulvegablog.devcamp.space/portfolio/portfolio_blogs", this.buildForm(), {withCredentials:true})
    .then(response => {
      this.props.handleSuccessfullFormSubmission(response.data);
    }).catch(error => {
        console.log("handlesubmit error for blog ", error)
    })
    event.preventDefault();
}
1 Answers

you can reload your page in then callback function by adding

window.location.reload()

like this

handleSubmit(event){
    event.preventDefault();
    axios.post("https://saulvegablog.devcamp.space/portfolio/portfolio_blogs", this.buildForm(), {withCredentials:true})
    .then(response => {
      this.props.handleSuccessfullFormSubmission(response.data);
      window.location.reload();
    }).catch(error => {
        console.log("handlesubmit error for blog ", error)
    })
}
Related