last day (15 days later) » 

12:10
2
A: page refreshes when file is changed react

Rohan AgarwalIs it a default behaviour? : YES, it is. This is known as live-reloading where a change in your file refreshes your local server and restarts the app setting all state to initial ones. But the problem as you mentioned is that the state of the app is lost. There is another concept called hot-reloa...

thanks @Rohan for quick reply, In I remember it did not used to refresh the page but then I dont know what happened. I even tried to reinstall chrome, delete node modules and install them again but nothing worked :(
Sorry, didn't get you. Did you try by adding the code mentioned above in your index.js or index.ts file? This will prevent refreshing the app.
yes I added and it seems to work, but as you said react states wont be saved?
Yes for that as I mentioned , you need to use the react-hot-loader plugin and make some configuration changes. You can find many good articles on the web to do it. :)
ok thanks for you help,appreciated.
last question :), the module variable in your code, which package includes it? maybe 'react'?
12:10
Its from NodeModule. npm install --save-dev @types/webpack-env . You may need this.
I did not include anything and it works, theses are my imports:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
these are my imports
You would need that package if you are using Typescript.
ok, I dont use typescript
also, Im quite confused. I remember it did not refresh the page, but yesterday it started for some reason. I also did not have the code you provided
Did you change anything? Code editor?
I dont remember changing anything. I tried 3 different editos,still same. I even reinstalled chrome, removed node modules and installed dependencies from scratch
12:17
Okay. Am not quite sure about the reason. Will need to look into it. Rest be assured that its an expected behaviour and nothing to worry about. To be sure, try creating another app using CRA and play around to check its behaviour
ok thanks a lot for your effort, really helpful
Welcome :)

last day (15 days later) »