Skip to content

@lightfin/react

import { LightfinChart, useChartEffect, useChart } from '@lightfin/react'

Owns the chart’s lifecycle: creates it on mount, removes it on unmount, keeps event-handler props wired, and publishes the instance through a ref and to child feature components.

PropTypeNotes
optionsChartOptionsInputApplied once; change key to re-create.
instrumentInstrumentInfo | nullRe-applied when it changes.
className / style—On the container — give it a size.
onCrosshairMove(e | null) => voidCrosshair moved.
onDataChange(change) => voidSeries data changed.
onSeriesChange(series) => voidSeries added/replaced.
onOrderIntent(e) => voidOpts in the ”+” order button.
onCreate(chart) => voidCalled once with the instance.
childrenReactNodeFeature components (see below).

It also exposes the Chart via ref:

const ref = useRef<Chart>(null)
<LightfinChart ref={ref} style={{ height: 420 }} />

Runs fn(chart) against the chart from context whenever deps change, after the chart exists. The ideal place to add series, indicators, annotations or price lines. Return a cleanup function, like useEffect.

function Sma({ period }: { period: number }) {
useChartEffect(
chart => {
let handle: IndicatorHandle | undefined
chart
.addIndicator(import('@lightfin/core/indicators/sma'), { period })
.then(h => (handle = h))
return () => handle?.remove()
},
[period],
)
return null
}

Returns the Chart from context (or null before it’s created) — for components that need it outside an effect.