fn
useRefHistory
v0.0.15testeddemoTrack the change history of a ref with undo/redo, pause/resume, batching, and manual commits.
Examples
ts
const count = ref(0);
const { history, undo, redo, canUndo, canRedo } = useRefHistory(count);
count.value = 1;
count.value = 2;
undo(); // count.value === 1
redo(); // count.value === 2ts
// Deep tracking with bounded capacity and a custom serializer
const state = ref({ items: [] });
const { history } = useRefHistory(state, { deep: true, capacity: 10 });Demo
Loading demo…
Signature
ts
export function useRefHistory<Raw, Serialized = Raw>(
source: Ref<Raw>,
options: UseRefHistoryOptions<Raw, Serialized> ={ ... }Type Parameters
RawSerialized= RawParameters
| Parameter | Type | Description |
|---|---|---|
source | Ref<Raw, Raw> | The ref whose changes are tracked |
options? | UseRefHistoryOptions<Raw, Serialized> | Tracking options (`deep`, `flush`, `capacity`, `clone`, `dump`, `parse`, `eventFilter`, `shouldCommit`) |
Returns
UseRefHistoryReturn<Raw, Serialized>History records plus `undo`/`redo`/`commit`/`reset`/`clear`/`pause`/`resume`/`batch`/`dispose`