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/utils'

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