useStateHistory

Keep a value with its history and move back and forward through it.

This is custom React hooks, you need to follow the Basic Rules when you use it.

General

Undo and redo the changes of a value.

APIs

useStateHistory

const useStateHistory = <T>(initialValue: T) => [
  T,
  {
    set: (value: T) => void
    back: (steps?: number) => void
    forward: (steps?: number) => void
    reset: () => void
  },
  { history: T[]; current: number },
]
Edit this page on GitHub