0

I decided to move all logic from React Components into Action Creators. In order to do this, I migrate classic Redux action creators to async Redux-Thunk action creators.

The basic flow works excellent. But I do not know how to update Router from the async Action Creators :(

import axios from 'axios';
import * as dialogActions from './DialogActions';

export const login = (creds) => {
  return (dispatch) => {
    axios.post('/admin/login', creds)
      .then((res) => {
        localStorage.setItem("token", res.headers['authorization']);

        //Next line gives error
        this.props.history.push("/admin/home");

        dispatch(dialogActions.initErrorAction(false, ''));
      })
      .catch((err) => {
        console.log(err.message)
        dispatch(dialogActions.initErrorAction(true, 'Invalid email or password'));
      });
  }
}

So the question is: how to update Router from Redux-Thunk Action Creators?

Alex Fruzenshtein
  • 1,926
  • 3
  • 26
  • 44

0 Answers0