# thunk-action-creator

> Creates standardized, four-part asynchronous actions for redux-thunk.

Latest version **0.1.2** (published 2018-07-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install thunk-action-creator
pnpm add thunk-action-creator
yarn add thunk-action-creator
bun add thunk-action-creator
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2018-07-10 |
| First published | 2018-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Charles Stover |
| Maintainers | charlesstover |
| Keywords | async, asynchronous, react, redux, redux-thunk, thunk |

## Links

- npm: https://www.npmjs.com/package/thunk-action-creator
- Repository: https://github.com/CharlesStover/thunk-action-creator
- Homepage: https://github.com/CharlesStover/thunk-action-creator#readme
- Issues: https://github.com/CharlesStover/thunk-action-creator/issues
- npm.io page: https://npm.io/package/thunk-action-creator

## 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

- 0.1.2 (latest) — 2018-07-10
- 0.1.1 — 2018-07-10
- 0.1.0 — 2018-07-10

## README

# thunk-action-creator
Creates standardized, four-part asynchronous actions for redux-thunk.

## Use
```JS
import thunkActionCreator from 'thunk-action-creator';
const thunkAction = thunkActionCreator(
  url,
  body,
  createRequestAction,
  createReceiveAction,
  createErrorAction,
  createAbortAction,
  conditional
);
```

## Parameters

* ### url: string
  The URL to which you are dispatching a fetch request.

* ### body: any
  The contents which you are including in your fetch request _or_ a function that returns said contents.

* ### createRequestAction: (abortController: AbortController | null) => AnyAction
  An action creator that is called when your fetch request has been dispatched.
  #### Parameters
  * ##### abortController: AbortController | null
    An AbortController instance that controls that abort signal for the fetch request.

    If you desire to abort any of your fetch requests, you should store this instance in your redux state.

    If the user's browser does not support aborting requests, the value will be `null`.

* ### createReceiveAction: (content: Object | string, statusCode: number, headers: Headers) => AnyAction
  An action creator that is called when your fetch request has received a response.
  #### Parameters
  * ##### content: Object | string
    A JavaScript object or string with which the server responded to the request.
  * ##### statusCode: number
    The status code with which the server responded to the request.
  * ##### headers: Headers
    An instance of `Headers` that contains the headers with which the server responded to the request.

* ### createErrorAction: (error: string, statusCode: null | number) => AnyAction
  An action creator that is called when an error occurs.
  #### Parameters
  * ##### error: string
    A string containing the error message. This may be either a JavaScript error or the response from the server.
  * ##### statusCode: null | number
    The status code with which the server responded to the request. If no status code exists (such as during a JavaScript error), the value is `null`.

* ### createAbortAction: () => AnyAction
  An action creator that is called when the fetch request is aborted.

  _See also:_ createRequestAction / Parameters / abortController

* ### conditional: (state: any) => boolean
  If present, this function is called prior to the fetch request.

  If it returns true, the fetch request will continue. If it returns false, the entire asynchronous action will be ignored.
  #### Parameters
  * ##### state: any
    Your current redux state.

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