# effectful

> The easy way to handle side effects in [Redux](https://redux.js.org/)

Latest version **2.0.0** (published 2019-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install effectful
pnpm add effectful
yarn add effectful
bun add effectful
```

## 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 | 2.0.0 |
| Published | 2019-05-01 |
| First published | 2019-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 207.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Christoffer Artmann |
| Maintainers | artmann |
| Keywords | redux, effects, middleware, redux-middleware |

## Links

- npm: https://www.npmjs.com/package/effectful
- Repository: https://github.com/Artmann/effectful
- Homepage: https://github.com/Artmann/effectful#readme
- Issues: https://github.com/Artmann/effectful/issues
- npm.io page: https://npm.io/package/effectful

## 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.0.0 (latest) — 2019-05-01
- 1.1.0 — 2019-02-07
- 1.0.0 — 2019-02-06

## README

# Effectful

The easy way to handle side effects in [Redux](https://redux.js.org/)

[![build status](https://img.shields.io/travis/Artmann/effectful/master.svg?style=flat-square)](https://travis-ci.org/Artmann/effectful)
[![npm version](https://img.shields.io/npm/v/effectful.svg?style=flat-square)](https://www.npmjs.com/package/effectful)

```js
yarn add effectful
```

## Usage

Define your side effects as async or regular functions and specify which
actions you want them to be triggered by.

```js
// effects/index.js

const fetchTodos = async (state, action, dispatch) => {
  const { searchQuery } = state;
  const url = `https://my-api.com/todos?query=${searchQuery}`;

  try {
    const response = await fetch(url);
    const { todos} = await response.json();

    dispatch(fetchTodosSuccess(todos));
  } catch (error) {
    dispatch(fetchTodosFail(error));
  }
};

export default {
  APP_MOUNTED: fetchTodos,
  SEARCH_QUERY_CHANGED: fetchTodos
};
```

Then all you have to do is add the effectful middleware to your store.

```js
// store/index.js

import { createStore, applyMiddleware } from 'redux';
import applyEffects from 'effectful';
import todos from '../reducers';
import effects from '../effects';

const store = createStore(
  todos,
  applyMiddleware(applyEffects(effects));
);
```

If you want to run multiple effects when an action is dispatched you can pass an array of effects.

```
export default {
  APP_MOUNTED: [fetchTodos, logger],
  SEARCH_QUERY_CHANGED: fetchTodos
};
```

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