@djgould/react-use-undo

0.2.0 • Public • Published

React useUndo

This is an undo hook for React. It is a simple hook that allows you to undo changes to a value.

installation:

npm install @djgould/react-use-undo

usage:

import React from "react";
import { useUndo } from "@djgould/react-use-undo";

function App() {
  const [commands, addCommand, undo, redo] = useUndo(0);

  return (
    <div>
      <button onClick={() => addCommand(commands[commands.length] + 1)}>
        Increment
      </button>
      <button onClick={undo}>Undo</button>
      <button onClick={redo}>Redo</button>
      <p>last value: {commands[commands.length - 1]}</p>
    </div>
  );
}

Running tests

npm test

Readme

Keywords

none

Package Sidebar

Install

npm i @djgould/react-use-undo

Weekly Downloads

0

Version

0.2.0

License

none

Unpacked Size

8.55 kB

Total Files

10

Last publish

Collaborators

  • djgould