# react-use-log

> ![img](https://raw.githubusercontent.com/jaslioin/useLog/master/docs/demo.png)

Latest version **1.1.3** (published 2021-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-log
pnpm add react-use-log
yarn add react-use-log
bun add react-use-log
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2021-10-18 |
| First published | 2021-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 30.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jaslioin |
| Maintainers | jaspilon |
| Keywords | console.log, hook, react, logger, uselog, use-log |

## Links

- npm: https://www.npmjs.com/package/react-use-log
- Repository: https://github.com/jaslioin/useLog
- Homepage: https://github.com/jaslioin/useLog#readme
- Issues: https://github.com/jaslioin/useLog/issues
- npm.io page: https://npm.io/package/react-use-log

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2021-10-18
- 1.1.2 — 2021-10-09
- 1.1.1 — 2021-10-09
- 1.1.0 — 2021-10-09
- 1.0.6 — 2021-10-09
- 1.0.5 — 2021-10-09
- 1.0.4 — 2021-10-08
- 1.0.3 — 2021-10-08
- 1.0.2 — 2021-10-08

## README

# use-log

![img](https://raw.githubusercontent.com/jaslioin/useLog/master/docs/demo.png)

A React Hook shortcut to log state changes inside react component

Also a project to try out `tsdx`, a typescript library development tool

## Usage

### Basic

will execute the default styled `console.log(state)` upon state change

```ts
  const App = ()=>{
    const [state,setState] = useState({a:1})

    useLog(state)

    return </>
  }

```

### Options

```ts
export type LoggerType =
  | 'debug'
  | 'error'
  | 'info'
  | 'log'
  | 'warn'
  | 'dir'
  | 'dirxml'
  | 'table'
  | 'trace'
  | 'group'
  | 'groupCollapsed'
  | 'groupEnd'
  | 'clear'
  | 'count'
  | 'countReset'
  | 'assert'
  | 'profile'
  | 'profileEnd'
  | 'time'
  | 'timeLog'
  | 'timeEnd'
  | 'timeStamp';

export type WithLoggerType = {
  loggerType?: LoggerType;
  previousStateLoggerType?: LoggerType;
};
export type WithLogger = {
  logger?: (value: any, label?: string) => void;
  previousStateLogger?: (value: any, label?: string) => void;
};
export type CommonOptions = {
  logPreviousValue?: boolean;
  isGrouped?: boolean;
};
export type Options = CommonOptions & (WithLogger | WithLoggerType | {});
```

- `Options.loggerType`

  when using `options.loggerType`, pass a string representing logging functions under `console`

```ts
useLog(state, 'my state', {
  loggerType: 'table',
});
```

- `Options.logger`

  when using `options.logger`, pass a `function` wrapping the native logging api

```ts
useLog(state, 'my state', {
  logger: (v: any, label?: string) =>
    console.log('%c%s', 'color:red', label, v),
});
```

## Caveat

**do not directly pass `console.*` as `logger`**

- react will override it into `disabledLog` to prevent it from logging

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