pmmmwh / react-refresh-webpack-plugin

A Webpack plugin to enable "Fast Refresh" (also previously known as Hot Reloading) for React components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rewrite window.fetch method It will not work!

renzhaoz opened this issue · comments

commented

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;
}