Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/sandiiarov/use-simple-undo

🔄 Simple solution to handle undo\redo turned into React Hooks
https://github.com/sandiiarov/use-simple-undo

Last synced: 2 months ago
JSON representation

🔄 Simple solution to handle undo\redo turned into React Hooks

Lists

README

        

![npm](https://img.shields.io/npm/dt/use-simple-undo.svg)
![npm](https://img.shields.io/npm/v/use-simple-undo.svg)
![NpmLicense](https://img.shields.io/npm/l/use-simple-undo.svg)

**Use Simple Undo** - Simple solution to handle undo\redo turned into React Hooks.
Read about [Hooks](https://reactjs.org/docs/hooks-intro.html) feature.

## Documentation

https://sandiiarov.github.io/use-simple-undo

## Installation

> Note: React 16.8+ is required for Hooks.

### With npm

```sh
npm i use-simple-undo
```

### Or with yarn

```sh
yarn add use-simple-undo
```

## Usage

```jsx
import useSimpleUndo from 'use-simple-undo';
```

```jsx
const Counter = () => {
const [state, cursor, setValue, { undo, redo }] = useSimpleUndo(0);

const value = state[cursor];

const increment = () => setValue(value + 1);
const decrement = () => setValue(value - 1);

return (
<>

{value}

increment
decrement
undo
redo
>
);
};
```