# promise-middleware-redux

> ## Usage ### Import to redux store file ```js import { createStore, applyMiddleware } from 'redux'; import reducer from './reducers'; import { promiseMiddleware } from 'promise-middleware-redux';

Latest version **1.2.0** (published 2019-06-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install promise-middleware-redux
pnpm add promise-middleware-redux
yarn add promise-middleware-redux
bun add promise-middleware-redux
```

## 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.2.0 |
| Published | 2019-06-10 |
| First published | 2019-03-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ryan Mehta |
| Maintainers | mehtaphysical |

## Links

- npm: https://www.npmjs.com/package/promise-middleware-redux
- Repository: https://github.com/alchemycodelab/promise-middleware-redux
- Homepage: https://github.com/alchemycodelab/promise-middleware-redux#readme
- Issues: https://github.com/alchemycodelab/promise-middleware-redux/issues
- npm.io page: https://npm.io/package/promise-middleware-redux

## Dependencies (1)

- [redux](https://npm.io/package/redux.md) ^4.0.1

## Recent versions

- 1.2.0 (latest) — 2019-06-10
- 1.1.1 — 2019-06-03
- 1.1.0 — 2019-06-03
- 1.0.6 — 2019-05-30
- 1.0.5 — 2019-03-06
- 1.0.4 — 2019-03-06
- 1.0.3 — 2019-03-06
- 1.0.2 — 2019-03-06
- 1.0.1 — 2019-03-06
- 1.0.0 — 2019-03-06

## README

# Promise Middleware

## Usage
### Import to redux store file
```js
import { createStore, applyMiddleware } from 'redux';
import reducer from './reducers';
import { promiseMiddleware } from 'promise-middleware-redux';

export default createStore(
  reducer,
  applyMiddleware(promiseMiddleware),
);
```


### Redux action
```js
export const fetchFacts = () => ({
  type: 'FETCH_FACTS',
  payload: getFacts()
});
```

```js
export const fetchFacts = () => ({
  type: 'FETCH_FACTS',
  pendingType: 'FETCH_FACTS_LOADING',
  fulfilledType: 'FETCH_FACTS_DONE',
  rejectedType: 'FETCH_FACTS_ERROR',
  payload: getFacts()
});
```

### Action Creator

```js
export const [
  fetchFacts, // this is an action creator
  FETCH_FACTS,
  FETCH_FACTS_PENDING,
  FETCH_FACTS_FULFILLED
  FETCH_FACTS_REJECTED
] = createAction('FETCH_FACTS', getFacts);
```
* `fetchFacts` is an action creator
* `FETCH_FACTS` is an action type that is dispatched when the promise
  fulfills. This action will include a `payload` with the fulfilled value.
* `FETCH_FACTS_PENDING` is an action type that is dispatched before
  the promise fulfills.
* `FETCH_FACTS_FULFILLED` is an action type that is dispatched if
  the promise fulfills.
* `FETCH_FACTS_REJECTED` is an action type that is dispatched if
  the promise rejects. This action will also include a `payload`
  with an error.
* `createAction` is a function that takes the name of an action type and a promise and returns all of the above in an array.

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