# react-usedebuglog

> Use Javascript console.log as hook

Latest version **1.0.8** (published 2020-12-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-usedebuglog
pnpm add react-usedebuglog
yarn add react-usedebuglog
bun add react-usedebuglog
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2020-12-08 |
| First published | 2020-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anthony Tran Van |
| Maintainers | tonydtran |

## Links

- npm: https://www.npmjs.com/package/react-usedebuglog
- Repository: https://github.com/tonydtran/react-usedebuglog
- Issues: https://github.com/tonydtran/react-usedebuglog/issues
- npm.io page: https://npm.io/package/react-usedebuglog

## Recent versions

- 1.0.8 (latest) — 2020-12-08
- 1.0.7 — 2020-12-03
- 1.0.6 — 2020-12-03
- 1.0.5 — 2020-12-03
- 1.0.4 — 2020-12-03
- 1.0.3 — 2020-12-03
- 1.0.2 — 2020-12-03
- 1.0.1 — 2020-12-03

## README

# react-usedebuglog

[![react-usedebuglog.png](https://i.postimg.cc/VLpM10wN/react-usedebuglog.png)](https://postimg.cc/svP14XvF)

## Get Started
```
yarn add react-usedebuglog
```
## Usage
First, import `DebugLogProvider` in your app root:
```
// index.js

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import DebugLogProvider 'react-usedebuglog'

ReactDOM.render(
  <DebugLogProvider dev={process.ENV.NODE_ENV === 'development'}>
    <App />
  </DebugLogProvider>,
  document.getElementById('root')
)
```

Then, import `useDebugLog` in your component:
```
// App.js

import { useDebugLog } from 'react-usedebuglog'

function App() {
  const c = useDebugLog('App')
  c.log('Hello, World')

  return (
    <div>
      ...
    </div>
  )
}
```

## References
### `DebugLogProvider` props:
- `dev`: Boolean, required. Set as `true` to enable logs by default in your components. Default: `false`.

### `useDebugLog` arguments:
```
const c = useDebugLog(<componentName>, <colors>, <enable>)
```
- `componentName`: String, required. Your current component name. Ex: 'MyComponent'.
- `colors`: Object, optional. Customize label color and background color. By default, `{ color: 'inherit', backgroundColor: 'blue'}`.
- `enable`: Boolean, optional. Enable logs within current component. By default, if `enable` has no value, it will take `dev` props value from `DebugLogProvider`, otherwise `enable` will locally override `dev` value.

Examples
```
const c = useDebugLog('MyComponent')
const c = useDebugLog('MyComponent', false)
const c = useDebugLog('MyComponent', { color: 'white', backgroundColor: 'gray' })
const c = useDebugLog('MyComponent', { color: '#32a852', backgroundColor: '#000000' }, true)
const c = useDebugLog('MyComponent', { color: '#32a852' }) // backgroundColor will be 'blue' by default
const c = useDebugLog('MyComponent', { backgroundColor: 'orange' }) // color will be 'inherit' by default
```

### `useDebugLog` methods:
react-usedebuglog provides those `console` Javascript methods:
- log
- table
- info
- error
- warn
- trace

Examples
```
c.log('Hello, World')
c.table({ a: 'Hello', b: 'World' })
```
Please refer to `console` documentation if needed https://developer.mozilla.org/en-US/docs/Web/API/Console

### Command
Can by useful in production environment. Assuming you've disabled logs within the entire app by setting `dev` as `false` or you've locally disabled by doing `const c = useDebugLog('MyComponent', false)`, you can manually enable logs in a mounted component directly from your web browser console:
```
useDebugLog.<componentName>(<enable>)

Example:
useDebugLog.MyComponent(true)   // To enable logs within this component
useDebugLog.MyComponent(false)  // To disable logs within this component
```
- `enable`: Boolean, `true` by default.

---
_Source: https://npm.io/package/react-usedebuglog · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
