HMR with React should work without having to manually refresh the rendered window
The console is correctly showing the updated / changed files. However, I have to press ctrl+r to actually see the changes on screen.
I've created a repo that was generated with the typescript-webpack template.
yarn and start with npm start. Open devtools with ctrl+alt+i.test.tsx. Notice that the console does show the updated file, but changes are not reflected.+1
I was able to make it work by not using
import { AppContainer } from 'react-hot-loader';
but instead using
// App.tsx
import { hot } from 'react-hot-loader';
import React from 'react';
const App = () => <div>Hello World!</div>;
export default hot(module)(App);
and
//renderer.tsx
import 'react-hot-loader';
import './index.css';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('app'));
See this repo for further questions. To reproduce the repro:
yarn create electron-app my-new-app --template=typescript-webpackyarn add react react-dom @types/react @types/react-dom react-hot-loader"jsx": "react", to tsconfig.json
webPreferences: {
nodeIntegration: true
} in index.ts{
"plugins": ["react-hot-loader/babel"]
}./src/renderer.ts to ./src/renderer.tsx in package.json<div id="app"></div> to index.htmlApp.tsx and renderer.tsx as shown aboveThen App.tsx should support hot reloading, what you can try out by changing the content of the div.
@TobiasJacob thanks a lot, this worked for me too :)
Thanks @TobiasJacob , I suppose that react-hot-loader shouldn't be used in production: export default hot(module)(App); ?
Most helpful comment
I was able to make it work by not using
but instead using
and
See this repo for further questions. To reproduce the repro:
yarn create electron-app my-new-app --template=typescript-webpackyarn add react react-dom @types/react @types/react-dom react-hot-loader"jsx": "react",totsconfig.jsonwebPreferences: { nodeIntegration: true }in index.ts{ "plugins": ["react-hot-loader/babel"] }./src/renderer.tsto./src/renderer.tsxin package.json<div id="app"></div>to index.htmlApp.tsxandrenderer.tsxas shown aboveThen App.tsx should support hot reloading, what you can try out by changing the content of the
div.