react-refresh-webpack-plugin icon indicating copy to clipboard operation
react-refresh-webpack-plugin copied to clipboard

Rewrite window.fetch method It will not work!

Open renzhaoz opened this issue 2 years ago • 0 comments

I use it in CRA application , when add token in request hot reload will be not work! here is the code!

import CloudUtils from './CloudUtils';

const oldFetch = fetch;

const newFetch = (url, options) => {
  const token = CloudUtils.getToken();
  const headers = options.headers || new Headers();
  headers.append('aaaa', `bearer ${token}`);
  options.headers = headers;

  return oldFetch(`${url}`, options);
};

if (window) {
  window.fetch = newFetch;
  window.oldFetch = oldFetch;
}

renzhaoz avatar Nov 01 '23 07:11 renzhaoz