valtio utility for creating a proxy state with history tracking
npm install valtio-historyvaltio utility for creating a proxy state with history tracking

https://valtio.pmnd.rs/docs/api/utils/proxyWithHistory
see detailed api docs for more info.
---
valtio/utils``tsx
// replace the following line
// import { proxyWithHistory } from 'valtio/utils';
import { proxyWithHistory } from 'valtio-history';
import { useSnapshot } from 'valtio';
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 }
// React example
export default function App() {
const {
value,
undo,
redo,
history,
isUndoEnabled,
isRedoEnabled,
currentChangeDate,
remove,
replace,
} = useSnapshot(state);
...
}
`
- the history object has changeshistory.snapshots
- is renamed to history.nodesHistoryNode
- a has the structure { snapshot: SnapshotproxyWithHistory
- The second parameter of is now an object instead of a boolean. { skipSubscribe?: boolean }`