Documentation / @finchart/react / useInfiniteHistory
Function: useInfiniteHistory()
useInfiniteHistory<
T,C>(options?):InfiniteHistoryState<T,C>
Defined in: react/src/hooks/use-infinite-history.ts:129
Infinite history whose place outlives the chart — the data, the load's paging and its token and end are held here, in the component that owns the data, and <InfiniteHistory history> inside the chart pages from there. A chart remounted under a key (a renko view, an error boundary's retry) resumes from the first bar held and the token last taken instead of asking for the first page again; a page landing for a load reset replaced is dropped.
tsx
const CANDLES = new OHLCAccessor(); // module level
const history = useInfiniteHistory<OHLC, string>({ coordinates: CANDLES });
const { reset } = history; // stable — `history` itself changes with every page
useEffect(() => {
let current = true;
api.candles(symbol).then((page) => {
if (current) reset(page.bars, { next: page.next, fetchPage: (cursor) => api.candles(symbol, cursor) });
});
return () => {
current = false;
};
}, [symbol, reset]);
<ChartContainer deps={deps} data={history.data}>
<ChartCandles />
<InfiniteHistory history={history} />
</ChartContainer>Type Parameters
T
T extends BaseDataPoint
C
C extends object = never
Parameters
options?
UseInfiniteHistoryOptions<T> = {}
Returns
InfiniteHistoryState<T, C>