I have created my first react-js app, just saying 'Hello world'. After I change the 'Hello world' to another text, nothing changes when I refresh the browser, even if I empty the cache. The changes take place only when I close the local server and reopen it with npm start. Could anyone help me?
-
Can you post your code so we can see whats going on? include your html and your component that has 'hello world'/changed text.iceveda06– iceveda062018-04-11 15:07:04 +00:00Commented Apr 11, 2018 at 15:07
Add a comment
|
2 Answers
If you want to create new react app from-scratch. You can use :
> npx create-react-app my-app
> cd my-app
> npm start
After that, you will have the initial configured react project structure :
my-app
├── README.md
├── node_modules
├── package.json
├── .gitignore
├── public
│ └── favicon.ico
│ └── index.html
│ └── manifest.json
└── src
└── App.css
└── App.js
└── App.test.js
└── index.css
└── index.js
└── logo.svg
└── registerServiceWorker.js
See react app seed in Github : https://github.com/facebook/create-react-app.
3 Comments
Ahmed Hussein
Would it be different if I follow this tutorial: tutorialspoint.com/reactjs/reactjs_environment_setup.htm ? Would this be the reason that I cannot refresh the browser ?
LaPoule
Yes, with
npx you don't need to a configure the webpack. You have a registerServiceWorker.js instead and your app is run with "start": "react-scripts start". In your tuto, it's start your app with "start": "webpack-dev-server --hot" in package.jsonLaPoule
Sam's answer is probably the best way to do it but if you want do refresh it without adding all the bells and whistles of create-react-app you can go for browsersync.
It watches over your CSS, HTML, JS. I usually use create-react-app but in some cases browsersync does the trick as well.