npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-undo-manager

v0.1.1

Published

A React hook that enables undo/redo history management with debounced state commits.

Readme

useUndoManager

A powerful React hook for managing undo/redo functionality with delayed commit and batch update support. Ideal for building complex, user-friendly state workflows such as form editors, drawing apps, and JSON builders.

npm version npm downloads License

Features

  • Undo & Redo with history management
  • Debounced (delayed) commits
  • Batch updates in commit window
  • View state vs Committed state separation
  • Lightweight and framework-agnostic
  • Manual merge for grouped commits
  • Pause/resume commit queue
  • Reset and flush utilities

Installation

npm install use-undo-manager

Simple Usage

import { useUndoManager } from "use-undo-manager";

function TextEditor() {
  const {
    state,
    committed,
    set,
    undo,
    redo,
    flush,
    mergeLast,
    reset,
    pause,
    resume,
    canUndo,
    canRedo,
  } = useUndoManager<string>("Hello", {
    commitDelay: 500,
    historyLimit: 100,
    onChange: (committedValue) => {
      console.log("Committed:", committedValue);
    },
  });

  return (
    <div>
      <input
        value={state}
        onChange={(e) => set(e.target.value)}
        placeholder="Type something..."
      />
      <button onClick={undo} disabled={!canUndo}>
        Undo
      </button>
      <button onClick={redo} disabled={!canRedo}>
        Redo
      </button>
      <button onClick={flush}>Flush</button>
      <button onClick={mergeLast}>Merge Last</button>
      <button onClick={pause}>Pause</button>
      <button onClick={resume}>Resume</button>
      <button onClick={() => reset("Hello")}>Reset</button>
    </div>
  );
}

⚙️ API

const result = useUndoManager<T>(initialState, options?)

Parameters:

| Name | Type | Default | Description | | -------------- | -------------------------- | ------- | ----------------------------------- | | initialState | T | — | Initial value for the state | | options | UseUndoManagerOptions<T> | {} | Optional settings for customization |

Options:

interface UseUndoManagerOptions<T> {
  /** Delay in milliseconds to commit changes (debounce window) */
  commitDelay?: number;

  /** Maximum number of undo/redo history entries to keep */
  historyLimit?: number;

  /** Callback called when the committed state changes */
  onChange?: (state: T) => void;
}

Return values

| Name | Type | Description | | ----------- | --------------------- | ------------------------------------------------------------- | | state | T | Current view state that updates immediately | | committed | T | Last committed state (used for undo/redo history) | | set | (value: T) => void | Updates the state; commits after debounce delay | | undo | () => void | Undo the last committed change | | redo | () => void | Redo the last undone change | | flush | () => void | Immediately commits any pending changes | | mergeLast | () => void | Replaces last committed state with current view state (batch) | | pause | () => void | Temporarily pauses committing changes | | resume | () => void | Resumes committing after pause | | reset | (value?: T) => void | Resets state and clears history | | canUndo | boolean | Whether undo is currently possible | | canRedo | boolean | Whether redo is currently possible |

Concepts

  • viewState: State immediately updated by set(). Used in UI.
  • committedState: State committed after debounce delay. Used in undo/redo history.
  • pendingStack: Queue of values waiting to be committed.
  • undoStack / redoStack: History stacks for state changes.

Advanced Use Cases

  • Grouping complex state transitions using mergeLast()
  • Temporarily disabling commits during programmatic changes via pause()/resume()
  • Manually controlling timing of batch commits with flush()

Contributing

Feel free to open issues or pull requests! If you have ideas or edge cases you’d like supported, let’s discuss it on GitHub.