score:1

you could do something like this:

edit: make sure you are passing the history prop to the action, or make the push when you're using the action on the component.

const createproject = (project, history) => async dispatch => {
  try {
    await axios.post('http://localhost:8080/api/project', project)
    history.push('/')       // <---- make the push here only after post success.
  } catch(error) {
    dispatch({
        type: get_errors,
        payload: error.response.data
      });
  }
};

try catch block then a history push to a different route.

alternatively:

const createprojecthandler = async () => {
  createproject(project).then(() => {
    props.history.push('/')
  })

}

this only works when you're returning the axios call. i'm not sure if its the same with async and await.


Related Query

More Query from same tag