{"id":40476379,"url":"https://github.com/pvvng/use-undo-manager","last_synced_at":"2026-01-20T18:24:47.448Z","repository":{"id":305982976,"uuid":"1024620059","full_name":"pvvng/use-undo-manager","owner":"pvvng","description":"A React hook that enables undo/redo history management with debounced state commits.","archived":false,"fork":false,"pushed_at":"2025-07-23T02:48:51.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-03T20:19:00.805Z","etag":null,"topics":["react","react-hooks","react-state-management","undo-redo"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pvvng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-23T02:11:06.000Z","updated_at":"2025-08-01T08:15:39.000Z","dependencies_parsed_at":"2025-07-23T02:47:46.405Z","dependency_job_id":"7191ce6d-8f07-45a0-8070-81b8e9c85b22","html_url":"https://github.com/pvvng/use-undo-manager","commit_stats":null,"previous_names":["pvvng/use-undo-manager"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pvvng/use-undo-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvvng%2Fuse-undo-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvvng%2Fuse-undo-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvvng%2Fuse-undo-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvvng%2Fuse-undo-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pvvng","download_url":"https://codeload.github.com/pvvng/use-undo-manager/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvvng%2Fuse-undo-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28609055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","react-hooks","react-state-management","undo-redo"],"created_at":"2026-01-20T18:24:47.314Z","updated_at":"2026-01-20T18:24:47.418Z","avatar_url":"https://github.com/pvvng.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useUndoManager\n\nA 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.\n\n[![npm version](https://img.shields.io/npm/v/use-undo-manager.svg?style=flat-square)](https://www.npmjs.com/package/use-undo-manager)\n[![npm downloads](https://img.shields.io/npm/dw/use-undo-manager.svg?style=flat-square)](https://www.npmjs.com/package/use-undo-manager)\n[![License](https://img.shields.io/npm/l/use-undo-manager.svg?style=flat-square)](LICENSE)\n\n## Features\n\n- Undo \u0026 Redo with history management\n- Debounced (delayed) commits\n- Batch updates in commit window\n- View state vs Committed state separation\n- Lightweight and framework-agnostic\n- Manual merge for grouped commits\n- Pause/resume commit queue\n- Reset and flush utilities\n\n## Installation\n\n```bash\nnpm install use-undo-manager\n```\n\n## Simple Usage\n\n```tsx\nimport { useUndoManager } from \"use-undo-manager\";\n\nfunction TextEditor() {\n  const {\n    state,\n    committed,\n    set,\n    undo,\n    redo,\n    flush,\n    mergeLast,\n    reset,\n    pause,\n    resume,\n    canUndo,\n    canRedo,\n  } = useUndoManager\u003cstring\u003e(\"Hello\", {\n    commitDelay: 500,\n    historyLimit: 100,\n    onChange: (committedValue) =\u003e {\n      console.log(\"Committed:\", committedValue);\n    },\n  });\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput\n        value={state}\n        onChange={(e) =\u003e set(e.target.value)}\n        placeholder=\"Type something...\"\n      /\u003e\n      \u003cbutton onClick={undo} disabled={!canUndo}\u003e\n        Undo\n      \u003c/button\u003e\n      \u003cbutton onClick={redo} disabled={!canRedo}\u003e\n        Redo\n      \u003c/button\u003e\n      \u003cbutton onClick={flush}\u003eFlush\u003c/button\u003e\n      \u003cbutton onClick={mergeLast}\u003eMerge Last\u003c/button\u003e\n      \u003cbutton onClick={pause}\u003ePause\u003c/button\u003e\n      \u003cbutton onClick={resume}\u003eResume\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e reset(\"Hello\")}\u003eReset\u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n## ⚙️ API\n\n### `const result = useUndoManager\u003cT\u003e(initialState, options?)`\n\n#### Parameters:\n\n| Name           | Type                       | Default | Description                         |\n| -------------- | -------------------------- | ------- | ----------------------------------- |\n| `initialState` | `T`                        | —       | Initial value for the state         |\n| `options`      | `UseUndoManagerOptions\u003cT\u003e` | `{}`    | Optional settings for customization |\n\n#### Options:\n\n```ts\ninterface UseUndoManagerOptions\u003cT\u003e {\n  /** Delay in milliseconds to commit changes (debounce window) */\n  commitDelay?: number;\n\n  /** Maximum number of undo/redo history entries to keep */\n  historyLimit?: number;\n\n  /** Callback called when the committed state changes */\n  onChange?: (state: T) =\u003e void;\n}\n```\n\n---\n\n### Return values\n\n| Name        | Type                  | Description                                                   |\n| ----------- | --------------------- | ------------------------------------------------------------- |\n| `state`     | `T`                   | Current view state that updates immediately                   |\n| `committed` | `T`                   | Last committed state (used for undo/redo history)             |\n| `set`       | `(value: T) =\u003e void`  | Updates the state; commits after debounce delay               |\n| `undo`      | `() =\u003e void`          | Undo the last committed change                                |\n| `redo`      | `() =\u003e void`          | Redo the last undone change                                   |\n| `flush`     | `() =\u003e void`          | Immediately commits any pending changes                       |\n| `mergeLast` | `() =\u003e void`          | Replaces last committed state with current view state (batch) |\n| `pause`     | `() =\u003e void`          | Temporarily pauses committing changes                         |\n| `resume`    | `() =\u003e void`          | Resumes committing after pause                                |\n| `reset`     | `(value?: T) =\u003e void` | Resets state and clears history                               |\n| `canUndo`   | `boolean`             | Whether undo is currently possible                            |\n| `canRedo`   | `boolean`             | Whether redo is currently possible                            |\n\n## Concepts\n\n- viewState: State immediately updated by set(). Used in UI.\n- committedState: State committed after debounce delay. Used in undo/redo history.\n- pendingStack: Queue of values waiting to be committed.\n- undoStack / redoStack: History stacks for state changes.\n\n## Advanced Use Cases\n\n- Grouping complex state transitions using mergeLast()\n- Temporarily disabling commits during programmatic changes via pause()/resume()\n- Manually controlling timing of batch commits with flush()\n\n## Contributing\n\nFeel free to open issues or pull requests!\nIf you have ideas or edge cases you’d like supported, let’s discuss it on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvvng%2Fuse-undo-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpvvng%2Fuse-undo-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvvng%2Fuse-undo-manager/lists"}