useDebouncedHistory
A hook that tracks Observable change history with debounce.
A thin wrapper around useHistory with debounceFilter applied — it only records history after typing has stopped. Ideal for text inputs or search fields where you want to snapshot only when a burst of changes has “settled”.
Rapid typing stays fluid, but history records only after the input has been idle for 600ms.
Type quickly, pause, then inspect how only the settled value lands in history.
Newest snapshot is pinned at the top.
import { function useObservable<T>(): Observable<T | undefined> (+3 overloads)
A React hook that creates a new observable
useObservable } from "@legendapp/state/react";import { import useDebouncedHistory
useDebouncedHistory } from "@usels/web";
const const search$: any
search$ = useObservable<unknown>(value: Promise<unknown> | (() => unknown) | unknown, deps?: React.DependencyList): any (+3 overloads)
A React hook that creates a new observable
useObservable("");
// Record a snapshot 500ms after the user stops typingconst { const undo: any
undo, const redo: any
redo, const canUndo$: any
canUndo$ } = import useDebouncedHistory
useDebouncedHistory(const search$: any
search$, { debounce: number
debounce: 500 });maxWait — force commit after maximum delay
Section titled “maxWait — force commit after maximum delay”Even if the user keeps typing, a snapshot is forced after maxWait ms.
import { function useObservable<T>(): Observable<T | undefined> (+3 overloads)
A React hook that creates a new observable
useObservable } from "@legendapp/state/react";import { import useDebouncedHistory
useDebouncedHistory } from "@usels/web";
const const text$: any
text$ = useObservable<unknown>(value: Promise<unknown> | (() => unknown) | unknown, deps?: React.DependencyList): any (+3 overloads)
A React hook that creates a new observable
useObservable("");
// Commit after 500ms idle, or every 2s at most even if still typingconst { const undo: any
undo, const redo: any
redo } = import useDebouncedHistory
useDebouncedHistory(const text$: any
text$, { debounce: number
debounce: 500, maxWait: number
maxWait: 2000,});Combined with capacity
Section titled “Combined with capacity”import { function useObservable<T>(): Observable<T | undefined> (+3 overloads)
A React hook that creates a new observable
useObservable } from "@legendapp/state/react";import { import useDebouncedHistory
useDebouncedHistory } from "@usels/web";
const const note$: any
note$ = useObservable<unknown>(value: Promise<unknown> | (() => unknown) | unknown, deps?: React.DependencyList): any (+3 overloads)
A React hook that creates a new observable
useObservable("");
const { const undo: any
undo, const redo: any
redo } = import useDebouncedHistory
useDebouncedHistory(const note$: any
note$, { debounce: number
debounce: 800, capacity: number
capacity: 30,});Type Declarations
Section titled “Type Declarations”export type UseDebouncedHistoryOptions<Raw, Serialized = Raw> = Omit<UseHistoryOptions<Raw, Serialized>, "eventFilter"> & { debounce?: MaybeObservable<number>; maxWait?: MaybeObservable<number>;};export type UseDebouncedHistoryReturn<Raw, Serialized = Raw> = UseHistoryReturn<Raw, Serialized>;export declare function useDebouncedHistory<Raw, Serialized = Raw>(source$: Observable<Raw>, options?: DeepMaybeObservable<UseDebouncedHistoryOptions<Raw, Serialized>>): UseDebouncedHistoryReturn<Raw, Serialized>;Source
Section titled “Source”Contributors
Section titled “Contributors”- tigerwest
Changelog
Section titled “Changelog”a7392ab2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)