Myself I prefer a debug function which accepts a function so anything can be run in debug mode. It's a little more verbose, but very flexible. This React env implementation has a flag for production which may or may not be desirable.
const debug = (fn: () => void) => { const env = process.env.REACT_APP_ENV; const hasFlag = window.location.search.includes('debug=true'); if (env === 'production' && !hasFlag) return; if (fn && typeof fn === 'function') fn(); }; export default debug;
debug(() => console.log('debugging'));
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Myself I prefer a debug function which accepts a function so anything can be run in debug mode. It's a little more verbose, but very flexible. This React env implementation has a flag for production which may or may not be desirable.