1. API
  2. proxyWithHistory

proxyWithHistory

Keep a history of snapshots

This is a utility function to create a proxy with snapshot history.

import { proxyWithHistory } from 'valtio-history'

const state = proxyWithHistory({ count: 0 })
console.log(state.value) // ---> { count: 0 }
state.value.count += 1
console.log(state.value) // ---> { count: 1 }
state.undo()
console.log(state.value) // ---> { count: 0 }
state.redo()
console.log(state.value) // ---> { count: 1 }

Codesandbox demo

Error embedding https://codesandbox.io/s/valtio-history-example-v0-m353xc?file=%2Fsrc%2FApp.tsx&codemirror=1&fontsize=14&hidenavigation=1&theme=light&hidedevtools=1.