I was working on a project with some local software house developer and what i notice is they use to much console's in application and these console are all in from local/development to production which is really bad for the application , so i decided to work on it and make a solution to this, we can create a custom function which will work for use to console data on some specific environment like on local/development but not on production,
i just create a util folder and in it i create a file name utils.js in which i define a function
in this example you can see i just create a function with name "consoleLog" which console the data with string which comes from parameter pass to this function, ignore the env and if condition , now this console will work on every environment and console dat,
but we want to console data only in development
npm i react-dotenv install this library and create .env file on your root folder, and then see the previous logic.
you can also just do a simple logic in root/app file in componentDidMount/userEfect with
Top comments (5)
You could also disable console.log in production?
Yes you can also define simple logic in app/root file and make console.log func to empty function, thanks for this suggestion.
Ideally, you would use eslint to highlight them all. Then, before accepting the changes, go and remove them.
sorry didn't get your point
Don't let console.log make it to production. Edit them out. eslint can read the code and warn you