useThrottledHistory
A hook that tracks Observable change history with throttle.
A thin wrapper around useHistory with throttleFilter applied — for rapidly changing values like sliders or drag interactions, it records snapshots at fixed intervals instead of on every change.
For fast-moving values like sliders, history records at most once every 300ms instead of saving every intermediate frame.
Drag aggressively and notice how the timeline keeps only periodic checkpoints.
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 useThrottledHistory
useThrottledHistory } from "@usels/web";
const const slider$: any
slider$ = useObservable<unknown>(value: Promise<unknown> | (() => unknown) | unknown, deps?: React.DependencyList): any (+3 overloads)
A React hook that creates a new observable
useObservable(50);
// Record at most once every 300msconst { const undo: any
undo, const redo: any
redo, const canUndo$: any
canUndo$ } = import useThrottledHistory
useThrottledHistory(const slider$: any
slider$, { throttle: number
throttle: 300 });leading / trailing edges
Section titled “leading / trailing edges”By default both leading and trailing edges fire. Disable either to customize behavior.
import { function useObservable<T>(): Observable<T | undefined> (+3 overloads)
A React hook that creates a new observable
useObservable } from "@legendapp/state/react";import { import useThrottledHistory
useThrottledHistory } from "@usels/web";
const const value$: any
value$ = useObservable<unknown>(value: Promise<unknown> | (() => unknown) | unknown, deps?: React.DependencyList): any (+3 overloads)
A React hook that creates a new observable
useObservable(0);
// Only record on the trailing edge (end of throttle window)const { const undo: any
undo } = import useThrottledHistory
useThrottledHistory(const value$: any
value$, { throttle: number
throttle: 500, leading: boolean
leading: false, trailing: boolean
trailing: true,});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 useThrottledHistory
useThrottledHistory } from "@usels/web";
const const position$: any
position$ = useObservable<unknown>(value: Promise<unknown> | (() => unknown) | unknown, deps?: React.DependencyList): any (+3 overloads)
A React hook that creates a new observable
useObservable({ x: number
x: 0, y: number
y: 0 });
const { const undo: any
undo, const redo: any
redo } = import useThrottledHistory
useThrottledHistory(const position$: any
position$, { throttle: number
throttle: 200, capacity: number
capacity: 20, // keep at most 20 throttled snapshots});Type Declarations
Section titled “Type Declarations”export type UseThrottledHistoryOptions<Raw, Serialized = Raw> = Omit<UseHistoryOptions<Raw, Serialized>, "eventFilter"> & { throttle?: MaybeObservable<number>; trailing?: boolean; leading?: boolean;};export type UseThrottledHistoryReturn<Raw, Serialized = Raw> = UseHistoryReturn<Raw, Serialized>;export declare function useThrottledHistory<Raw, Serialized = Raw>(source$: Observable<Raw>, options?: DeepMaybeObservable<UseThrottledHistoryOptions<Raw, Serialized>>): UseThrottledHistoryReturn<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)