Skip to content

Commit

Permalink
feat(Console): provide a mean to log only in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pylafleur committed Mar 28, 2024
1 parent 65199d6 commit 3bb2dac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/react/src/hooks/use-dev-console.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type DevConsole = Pick<Console, 'log' | 'info' | 'warn' | 'error'>;

// eslint-disable-next-line no-underscore-dangle
const inDevMode = globalThis.__DS_DEV__;

// eslint-disable-next-line @typescript-eslint/no-empty-function
function noop(): void {}

export function useDevConsole(): DevConsole {
return {
log: inDevMode ? console.log : noop,

Check failure on line 11 in packages/react/src/hooks/use-dev-console.ts

View workflow job for this annotation

GitHub Actions / React: ESLint

ESLint results

Unexpected console statement.
info: inDevMode ? console.info : noop,
warn: inDevMode ? console.warn : noop,
error: inDevMode ? console.error : noop,
};
}
5 changes: 5 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// eslint-disable-next-line no-underscore-dangle, no-var, vars-on-top
declare global { var __DS_DEV__: boolean; }
// eslint-disable-next-line no-underscore-dangle
global.__DS_DEV__ = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test';

// Buttons
export { Button } from './components/buttons/button';
export { IconButton } from './components/buttons/icon-button';
Expand Down

0 comments on commit 3bb2dac

Please sign in to comment.