# bind-promise-to-dispatch

> use dispatch as Promise in redux-saga

Latest version **1.0.2** (published 2019-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install bind-promise-to-dispatch
pnpm add bind-promise-to-dispatch
yarn add bind-promise-to-dispatch
bun add bind-promise-to-dispatch
```

## 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.2 |
| Published | 2019-02-19 |
| First published | 2018-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zewail Chan |
| Maintainers | zewail |
| Keywords | react, redux, dispatch, redux-saga |

## Links

- npm: https://www.npmjs.com/package/bind-promise-to-dispatch
- npm.io page: https://npm.io/package/bind-promise-to-dispatch

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.3.1

## 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.0.2 (latest) — 2019-02-19
- 1.0.1 — 2019-02-19
- 1.0.0 — 2018-09-06

## README

# bindPromiseToDispatch
use dispatch as Promise in redux-saga

## Installation
```sh
$ npm i -S bind-promise-to-dispatch
```

## Usage
redux-saga
```js
// add resolve and reject paramers
function* foo({ payload, resolve = () => {}, reject = () => {} }) {
  // try to get api data
  try {
    // success flow
    const res = yield call(request, payload)
    resolve(res)
  } catch (err) {
    // err flow
    reject(err)
  }
}
```
react component
```js
import bindPromiseToDispatch from 'bind-promise-to-dispatch'
import { connect } from 'react-redux'

@connect()
class Foo extends React.Component {
  constructor(props){
    super(props)
    this.state = {}
    this.promiseDispatch = bindPromiseToDispatch(this.props.dispatch)
  }

  componentDidMound() {
    this.promiseDispatch({
      type: 'xxx',
      payload: 'xxx'
    }).then(res => {
      // do something after get api data
    }).catch(err => {
      // catch something
    })
  }
}
```

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