Skip to content

djgould/react-use-undo

Repository files navigation

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

About

Undo hook for react

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published