You could include this interceptor code in the same place you have access to the redux store directly. Maybe in the file that you create your redux store (index.js)?
With that in place, you can dispatch the action directly from the redux store like that:
import reduxStore from './store';
import App from './components/App';
const router = (
<Provider store={reduxStore}>
<Router>
<Route path="/" component={App}/>
</Router>
</Provider>
);
/** Intercept any unauthorized request.
* dispatch logout action accordingly **/
const UNAUTHORIZED = 401;
const {dispatch} = reduxStore; // direct access to redux store.
axios.interceptors.response.use(
response => response,
error => {
const {status} = error.response;
if (status === UNAUTHORIZED) {
dispatch(userSignOut());
}
return Promise.reject(error);
}
);
render(router, document.getElementById('app-root'));