Acquiring a new token with `axios.interceptors`

When the token expires, I want to get a new token based on refresh_token. I have read that this can be obtained with axios.interceptors. Please check if I have correctly configured axios.interceptors and whether I have placed it in the right place, i.e. above theItems class.
axios.interceptors.response is assigned to theinterceptor variable. What should I do with this variable? In addition to `axios.interceptors’, I need to get a new token. The token is valid for 24 hours. I have to wait 24 hours to test whether it works, or is it possible in a different way, faster? Where should I put ‘client_id’, ‘secret_id’, ‘grant_type’?

Code here:

import axios from 'axios';

axios.defaults.baseURL = localStorage.getItem('domain');

const interceptor = axios.interceptors.response.use(
  response => response,
  error => {
      // Reject promise if usual error
      if (errorResponse.status !== 401) {
          return Promise.reject(error);

       * When response code is 401, try to refresh the token.
       * Eject the interceptor so it doesn't loop in case
       * token refresh causes the 401 response

      return'/api/refresh_token', {
          'refresh_token': JSON.parse(localStorage.getItem('token'))['refresh_token']
      }).then(response => {
          localStorage.setItem('token', JSON.stringify(;
          error.response.config.headers['Authorization'] = 'Bearer ' +;
          return axios(error.response.config);
      }).catch(error => {
          localStorage.setItem('token', '');
          return Promise.reject(error);

class Items extends Component {

  constructor (props) {
    this.state = {


  render () {
    return (
      <div >


render(<Items />, document.getElementById('root'));

Source: ReactJs