# redux-undo-action

> This is a reducer enhancer that will allow you to undo any action dispatched to the store.

Latest version **0.0.2** (published 2021-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-undo-action
pnpm add redux-undo-action
yarn add redux-undo-action
bun add redux-undo-action
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2021-03-03 |
| First published | 2021-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | ezequielzacca |
| Maintainers | ezequielzacca |

## Links

- npm: https://www.npmjs.com/package/redux-undo-action
- Repository: https://github.com/ezequielzacca/redux-undo-action
- Issues: https://github.com/ezequielzacca/redux-undo-action/issues
- npm.io page: https://npm.io/package/redux-undo-action

## Recent versions

- 0.0.2 (latest) — 2021-03-03
- 0.0.1 — 2021-03-03

## README

# Redux Undo Action

This is a reducer enhancer that will allow you to undo any action dispatched to the store.

## Installation

`npm i redux-undo-action`

## Configuration

You just need to wrap your top level reducer with the `undoable` function provided by `redux-undo-action`

```typescript
import { configureStore } from '@reduxjs/toolkit';
import counterReducer from '../features/counter/counterSlice';
import { undoable } from 'redux-undo-action';

export const store = configureStore({
  reducer: {
    counter: undoable(counterReducer),
  }
});

```

## How to use

To undo an action, just dispatch the `undo` action with the action that you want to undo as payload.

### Thunk example

```typescript
export const incrementOptimistic = (): AppThunk => async dispatch => {
  const optimisticAction = increment();
  dispatch(optimisticAction);
  try {
    await simulateCallServer();
  } catch (error) {
    console.log("There was an error... undoing")
    dispatch(undo(optimisticAction));
  }
};

```

### Saga example

```typescript
function* incrementCounterAsync() {
    const action = increment();
    try {
        yield put(action);
        yield simulateCallServer();
    } catch (e) {
        console.log("Error... undoing");
        yield put(undo(action));
    }
}

```

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