# resaga

> A reusable Reducer and Saga HOC library

Latest version **0.12.1** (published 2025-07-02) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 35/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.12.1 |
| Published | 2025-07-02 |
| First published | 2017-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 658.2 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Quan Do @UGROOP |
| Maintainers | quando |

## Links

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

## Dependencies (11)

- [redux](https://npm.io/package/redux.md) 4.0.1
- [lodash](https://npm.io/package/lodash.md) latest
- [reselect](https://npm.io/package/reselect.md) 4.0.0
- [immutable](https://npm.io/package/immutable.md) 4.0.0-rc.12
- [redux-saga](https://npm.io/package/redux-saga.md) ^1.0.2
- [re-reselect](https://npm.io/package/re-reselect.md) 3.4.0
- [react-redux](https://npm.io/package/react-redux.md) 7.2.9
- [redux-immutable](https://npm.io/package/redux-immutable.md) 4.0.0
- [lodash.difference](https://npm.io/package/lodash.difference.md) latest
- [dot-prop-immutable](https://npm.io/package/dot-prop-immutable.md) 1.6.0
- [string.prototype.padend](https://npm.io/package/string.prototype.padend.md) ^3.0.0

## Recent versions

- 0.12.1 (latest) — 2025-07-02
- 0.12.0 — 2025-07-02
- 0.10.0 — 2023-04-20
- 0.9.6 — 2020-08-12
- 0.9.4 — 2020-08-11
- 0.9.5 — 2020-04-03
- 0.9.0 — 2018-11-05
- 0.8.1 — 2018-07-25
- 0.0.22 — 2018-06-27
- 0.0.21 — 2018-06-20
- 0.0.20 — 2018-06-12
- 0.0.19 — 2018-04-10
- 0.0.18 — 2018-04-03
- 0.0.17 — 2018-02-06
- 0.0.16 — 2018-01-28
- … 14 more at https://npm.io/package/resaga/versions

## README

# React Resaga
[![npm version](https://badge.fury.io/js/resaga.svg)](https://www.npmjs.com/package/resaga)
[![codecov](https://codecov.io/gh/quandhz/resaga/branch/master/graph/badge.svg)](https://codecov.io/gh/quandhz/resaga)
[![Build Status](https://travis-ci.org/quandhz/resaga.svg?branch=master)](https://travis-ci.org/quandhz/resaga)

A reusable Reducer and Saga HOC library

### Documentation
https://resaga.quandh.com

### Install

```bash
npm install --save resaga
```

## Basic Usages
### Wrap your component by resaga HOC
```js
// MyBookPage.js
export class MyBookPage extends PureComponent {
  // ...
}

const configs = {
  name: 'MyBookPage',
  requests: {
    getBooks: () => fetch('get', '/api/books'),
  },
};
export default resaga(configs)(MyBookPage);
```
- `configs.name`: unique, work as an identification
- `requests.getBooks`: tell resaga what to do when 'getBooks' is dispatched
- `resaga(configs)(MyBookPage)` wrap MyBookPage by resaga HOC with your own configs

### Use the injected props
Props `resaga` will be attached to `MyBookPage` component
```js
// MyBookPage.js
componentDidMount = () => this.props.resaga.dispatch('getBooks');
componentWillReceiveProps = (nextProps) =>
  this.props.resaga.analyse(
    nextProps,
    { getBooks: { onSuccess: this.getBooksSuccess } }
  );
getBooksSuccess = (books) => {
  // will be called when server returns some results
}
```

### Inject resaga reducer and sagas to your route
This is based on reactboilerplate `routes.js` file
```js
const myBookPage = 'MyBookPage'; // should match `configs.page` that we set in the beginning
<Route
  path={'/books'}
  name={'My Book Page'}
  getComponent={(nextState, cb) => {
    const importModules = Promise.all([
      import('resaga'),
      import('containers/MyBookPage'),
    ]);

    const renderRoute = loadModule(cb);
    
    importModules.then(([resaga, component]) => {
      const reducer = resaga.reducer(myBookPage);
      injectReducer(myBookPage, reducer);
      injectSagas(resaga.sagas);
      renderRoute(component);
    });

    importModules.catch(errorLoading);
  }}
/>
```

## Tests!
Run them:
`npm run test:jest`

Check coverage:
`npm run coverage`

## Scripts
Run with `npm run <script>`.

### release
Takes the same argument as `npm publish`, i.e. `[major|minor|patch|x.x.x]`, then tags a new version, publishes, and pushes the version commit and tag to `origin/master`. Usage: `npm run release -- [major|minor|patch|x.x.x]`. Remember to update the CHANGELOG before releasing!

### build
Runs the build scripts detailed below.

### build:component
Transpiles the source in `lib/` and outputs it to `build/`, as well as creating a UMD bundle in `dist/`.

### test
Runs the test scripts detailed below.

### test:lint
Runs `eslint` on the source.

### test:jest
Runs the unit tests with `jest`.

### coverage
Runs the unit tests and creates a code coverage report.

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