https://github.com/wagnercsfilho/react-redux-undo
A simple redux state undo
https://github.com/wagnercsfilho/react-redux-undo
react redux undo
Last synced: about 1 year ago
JSON representation
A simple redux state undo
- Host: GitHub
- URL: https://github.com/wagnercsfilho/react-redux-undo
- Owner: wagnercsfilho
- Created: 2020-10-23T20:20:28.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-24T18:01:41.000Z (over 5 years ago)
- Last Synced: 2025-04-20T20:17:17.958Z (about 1 year ago)
- Topics: react, redux, undo
- Language: JavaScript
- Homepage: https://codesandbox.io/s/funny-solomon-9tv78
- Size: 97.7 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### React Redux Undo
A simple reducer enhancer (or a higher order reducer) that allows you to undo/redo changes in the state.
#### Install
```
npm install react-redux-undo
```
With yarn
```
yarn add react-redux-undo
```
#### Who to use
```jsx
import { createStore } from "redux";
import { applyUndo, ActionCreators } from "react-redux-undo";
const store = createStore(applyUndo(reducer));
function App() {
return (
);
}
function Count() {
const counter = useSelector((state) => state.counter);
const dispatch = useDispatch();
return (
Counter {counter}
dispatch({ type: "ADD" })}>ADD COUNTER
dispatch(ActionCreators.undo())}>UNDO
dispatch(ActionCreators.clear())}>CLEAR
dispatch(ActionCreators.redo())}>UNDO
);
}
```
#### Passing custom props
Defines a maximum size of the history stack
```js
applyUndo(reducer, { maxHistory: 5 });
```
#### Example
[Check an example](https://codesandbox.io/s/funny-solomon-9tv78)
#### License
MIT