Skip to content

useReplay

Replay historical candles at various speeds with play/pause/step controls and progress tracking.

import { useReplay } from "react-klinecharts-ui";
const {
isReplaying,
isPaused,
speed,
barIndex,
totalBars,
startReplay,
stopReplay,
togglePause,
stepForward,
stepBackward,
seekTo,
setSpeed,
} = useReplay();
// Opt-in: cap the buffered window for very long histories.
const capped = useReplay({ maxBars: 2000 });
PropertyTypeDescription
isReplayingbooleanWhether a replay session is active
isPausedbooleanWhether the replay is currently paused
speedReplaySpeedPlayback speed multiplier (1 | 2 | 5 | 10)
barIndexnumberCurrent bar index in the replay
totalBarsnumberTotal bars in the saved dataset
startReplay() => voidStart replaying from the beginning
stopReplay() => voidStop and restore the original data
togglePause() => voidToggle play/pause
stepForward() => voidAdvance one bar while paused
stepBackward() => voidGo back one bar while paused
seekTo(index: number) => voidSeek to a bar index (pauses playback)
setSpeed(speed: ReplaySpeed) => voidChange the playback speed

At higher speeds steps are grouped so the chart reloads at most 6 times per second (MAX_RELOADS_PER_SECOND) while keeping the same wall-clock pace. The optional useReplay({ maxBars }) caps how many trailing bars are buffered for the session (uncapped by default); totalBars then reflects the capped window.