# zustand-logger-middleware

> ### Installation:

Latest version **1.0.9** (published 2023-05-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install zustand-logger-middleware
pnpm add zustand-logger-middleware
yarn add zustand-logger-middleware
bun add zustand-logger-middleware
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2023-05-22 |
| First published | 2023-05-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | itsramiel |
| Keywords | zustand, zustand middleware, logger middleware, zustand log |

## Links

- npm: https://www.npmjs.com/package/zustand-logger-middleware
- Repository: https://github.com/itsramiel/zustand-logger-middleware
- Issues: https://github.com/itsramiel/zustand-logger-middleware
- npm.io page: https://npm.io/package/zustand-logger-middleware

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.9 (latest) — 2023-05-22
- 1.0.8 — 2023-05-22
- 1.0.7 — 2023-05-16
- 1.0.6 — 2023-05-16
- 1.0.5 — 2023-05-16
- 1.0.4 — 2023-05-15
- 1.0.3 — 2023-05-15
- 1.0.2 — 2023-05-15
- 1.0.1 — 2023-05-15
- 1.0.0 — 2023-05-15

## README

## Middleware for zustand to log the name of the function called as well as its arguments

### Installation:

npm:
`npm install zustand-logger-middleware`
yarn:
`yarn add zustand-logger-middleware`

### Usage:

There is one prerequisite to using the middleware and that is to put all functions/actions inside `action` object of the zustand store.

For example if you have the following zustand store:

```
type State = {
  count: number;
  actions: {
    increment: () => void;
    add: (value: number) => void;
  };
};

const store = create<State>()(
  (set) => ({
    count: 0,
    actions: {
      increment: () => set((prev) => ({ count: prev.count + 1 })),
      add: (value) => set((prev) => ({ count: prev.count + value })),
    },
  }),
);
```

You can use the logger middleware by simply passing a function that accepts two parameters which are the name of function called and the arguments passed to it.

Taking the earlier example and building on it would give us:

```
const store = create<State>()(
  logger(
    (set) => ({
      count: 0,
      actions: {
        increment: () => set((prev) => ({ count: prev.count + 1 })),
        add: (value) => set((prev) => ({ count: prev.count + value })),
      },
    }),
    (fnName, fnArgs) => {
      console.log(`${fnName} called with ${fnArgs}`);
    }
  )
);
```

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