Skip to main content
Module

x/valtio/docs/utils/proxyWithHistory.mdx

πŸ’Š Valtio makes proxy-state simple for React and Vanilla
Go to Latest
File
---title: 'proxyWithHistory'section: 'Utils'description: ''---
# proxyWithHistory
#### keep a history of snapshots
This is a utility function to create a proxy with snapshot history.
```jsimport { proxyWithHistory } from 'valtio/utils'
const state = proxyWithHistory({ count: 0 })console.log(state.value) // ---> { count: 0 }state.value.count += 1console.log(state.value) // ---> { count: 1 }state.undo()console.log(state.value) // ---> { count: 0 }state.redo()console.log(state.value) // ---> { count: 1 }```
## Codesandbox demo
https://codesandbox.io/s/admiring-wright-2oh2x?file=/src/App.tsx