# redux-dynamic-middlewares

> Allow add or remove redux middlewares dynamically

Latest version **2.2.0** (published 2022-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-dynamic-middlewares
pnpm add redux-dynamic-middlewares
yarn add redux-dynamic-middlewares
bun add redux-dynamic-middlewares
```

## 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 | 2.2.0 |
| Published | 2022-04-06 |
| First published | 2017-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | Denis Iogansen |
| Maintainers | pofigizm |
| Keywords | redux, dynamic, middleware |

## Links

- npm: https://www.npmjs.com/package/redux-dynamic-middlewares
- Repository: https://github.com/pofigizm/redux-dynamic-middlewares
- Homepage: https://github.com/pofigizm/redux-dynamic-middlewares#readme
- Issues: https://github.com/pofigizm/redux-dynamic-middlewares/issues
- npm.io page: https://npm.io/package/redux-dynamic-middlewares

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2022-04-06
- 0.6.1 (next) — 2018-08-28
- 2.1.0 — 2022-04-06
- 2.0.0 — 2020-01-10
- 1.0.0 — 2018-10-07
- 0.5.0 — 2018-08-28
- 0.4.0 — 2018-06-24
- 0.3.0 — 2018-01-06
- 0.2.1 — 2017-09-07
- 0.2.0 — 2017-09-07
- 0.1.3 — 2017-04-01
- 0.1.2 — 2017-04-01
- 0.1.1 — 2017-04-01
- 0.1.0 — 2017-02-23

## README

# redux-dynamic-middlewares

ℹ️ If you are building big redux app see [redux-dynamic](https://github.com/pofigizm/redux-dynamic).

[![npm version](https://img.shields.io/npm/v/redux-dynamic-middlewares.svg?style=flat-square)](https://www.npmjs.com/package/redux-dynamic-middlewares)
[![npm downloads](https://img.shields.io/npm/dm/redux-dynamic-middlewares.svg?style=flat-square)](https://www.npmjs.com/package/redux-dynamic-middlewares)

Allow add or remove redux middlewares dynamically (for example: on route change).

```
npm install --save redux-dynamic-middlewares
```

## Example

common usage:
```js

// configure store

import { createStore, applyMiddleware } from 'redux'
import rootReducer from './reducers/index'

import dynamicMiddlewares from 'redux-dynamic-middlewares'

const store = createStore(
  rootReducer,
  applyMiddleware(
    // ... other static middlewares
    dynamicMiddlewares
  )
)

// some other place in your code

import { addMiddleware, removeMiddleware, resetMiddlewares } from 'redux-dynamic-middlewares'

const myMiddleware = store => next => action => {
  // do something
  return next(action)
}

// will add middleware to existing chain
addMiddleware(myMiddleware /*[, anotherMiddleware ... ]*/)

// will remove middleware from chain (only which was added by `addMiddleware`)
removeMiddleware(myMiddleware)

// clean all dynamic middlewares
resetMiddlewares()

```

complex usage (when need many instances):
```js

// configure store

import { createStore, applyMiddleware } from 'redux'
import rootReducer from './reducers/index'

import { createDynamicMiddlewares } from 'redux-dynamic-middlewares'

const dynamicMiddlewaresInstance = createDynamicMiddlewares()

const store = createStore(
  rootReducer,
  applyMiddleware(
    // ... other static middlewares
    dynamicMiddlewaresInstance.enhancer
  )
)

// some other place in your code

const myMiddleware = store => next => action => {
  // do something
  return next(action)
}

// will add middleware to existing chain
dynamicMiddlewaresInstance.addMiddleware(myMiddleware /*[, anotherMiddleware ... ]*/)

// will remove middleware from chain (only which was added by `addMiddleware`)
dynamicMiddlewaresInstance.removeMiddleware(myMiddleware)

// clean all dynamic middlewares
dynamicMiddlewaresInstance.resetMiddlewares()

```

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