React create app hot reload is not always working on linux

后端 未结 9 1860
面向向阳花
面向向阳花 2020-12-24 12:03

I created a react application using create-react-app boilerplate, which seems to be very popular, hot reload some times updates when any of the files changes and some times

9条回答
  •  我在风中等你
    2020-12-24 12:53

    Apparently hot module reloading only works out-of-the-box if you eject your app.

    But if you haven't ejected your app, then you can follow these instructions to get it working.

    Find the ReactDOM.render(...) at the top of your app, and add these lines below it:

    ReactDOM.render(...);
    
    if (module.hot) {
      module.hot.accept('./App', () => {
        // --- Copy-paste your usual ReactDOM.render(...) call here: --- //
        ReactDOM.render(...);
      });
    }
    

    The instructions linked above also show how to hot reload things outside of the component tree, such as redux reducers.

提交回复
热议问题