1

I am trying Reactjs for the first time, but when want to render something, it only renders it when I restart my project. If I hit save, nothing happens. Have someone met with this problem yet?


import React from 'react';


function App(){
  return (
    <div>
      <h1>Hello React</h1>
      <button>Button</button>

    </div>
  );
}

export default App;
import React from 'react';
import ReactDOM from 'react-dom';


ReactDOM.render(<App />, document.getElementById('root'));
  • 3
    Do you mean it does not re-render when you edit the source files? – Sylens Aug 17 '19 at 11:21
  • see [webpack-dev-server does not watch for my file changes](https://stackoverflow.com/questions/29722755/webpack-dev-server-does-not-watch-for-my-file-changes) if it's the same problem – Aprillion Aug 17 '19 at 11:33
  • 1
    @Sylens yes. But I don't know how I managed it, but now it works fine. I re-installed create-react-app, and now when I edit App.js, it re-renders the content automatically when I hit save. – Balázs Márton Aug 18 '19 at 14:35
  • 1
    By the way, thank you guys all for your comments, I'm still trying to understand everything about web development.. :) – Balázs Márton Aug 18 '19 at 14:37

1 Answers1

1

If you want the app to render the latest changes you made to the source files, you have to implement hot-reloading.

Check this site for more info : https://gaearon.github.io/react-hot-loader/getstarted/

It will scan changes you do to the source files and automatically apply the changes to the running app. It will also make sure that the state of the app is not lost during this change.

Sylens
  • 1,097
  • 8
  • 31