0

When I make a change in my React app, it renders and shows my console.log(), but the previous console.logs() are not cleared automatically. This can be confusing. The app has been refreshed, but the console has not been cleared.

How do I change setting to clear previous console.log() each time, before it is rendered? I want to see only last console.log() in browser console. This should be done by React itself and not me manually.

Saeed sdns
  • 804
  • 7
  • 17
  • Does this answer your question? [clear javascript console in Google Chrome](https://stackoverflow.com/questions/3011600/clear-javascript-console-in-google-chrome) (Using this inside the relevant lifecycle method, depending on class/functional components, should do it) – DBS Aug 16 '21 at 16:11
  • @DBS No! It is relative to react or linter or webpack or package.json or etc. For example, in Angular, every thing is ok! – Saeed sdns Aug 16 '21 at 16:31
  • This depends on the hot reloader configuration you're using. You might be able to hook into a "hot reload done" event and call `console.clear()` there. – AKX Aug 16 '21 at 16:35
  • put a console.clear() to your App file :) – halilcakar Aug 16 '21 at 16:35
  • @AKX How should I do this? In my opinion, this solution can be the right solution. I want to a hot reload like page refreshing. – Saeed sdns Aug 16 '21 at 16:37
  • @halilcakar I know about console.clear(), but it is not my answer. This should not be done manually. React refreshes the page, so it should clear the console as well. – Saeed sdns Aug 16 '21 at 16:38
  • Well I got your point and it's easier putting a `console.clear()` to your app instead trying to find out about hot reload it's a choice obv. have it your way :) – halilcakar Aug 16 '21 at 16:40
  • @halilcakar Thanks so much :) but this is a tedious way to write console.clear() every time! A professional coder does not do this. This problem must be solved systematically by react, like angular. – Saeed sdns Aug 16 '21 at 16:52
  • 1
    @Saeedsdns As said, it depends on the hot reloader configuration. You're just saying you're using React; you could be using CRA, Vite, Rollup, a custom Webpack configuration, ... – AKX Aug 16 '21 at 17:23

0 Answers0