React
react-apexstock is a thin, typed React component around the imperative ApexStock class. It creates the instance on mount, forwards prop changes to update(), and tears it down on unmount.
Installation
npm install react-apexstock apexstock apexcharts
apexcharts, apexstock, react, and react-dom are peer dependencies. The wrapper requires apexstock >=0.5.0 <1 and apexcharts ^7.1.0 || ^8.0.0, and those two have to agree: apexstock 0.5.0 and later pair with ApexCharts 7.1 and later, so an older apexstock alongside apexcharts@7 will not resolve. ApexCharts 8 needs apexstock 0.5.2 and react-apexstock 0.2.3 or newer: apexstock 0.5.0 and 0.5.1 and react-apexstock 0.2.2 accept ^7.1.0 only. react-apexstock 0.2.3 takes the current apexstock 0.6.0 as it is.
To follow an Ignite UI theme, import the core's add-on once in the app, import 'apexstock/ignite-ui', not anything from the wrapper. It needs ApexCharts 8.8.0 or later. See Using with Ignite UI.
ApexCharts can reach the library three ways. Pass it to the component with the apexCharts prop, register it once app-wide with ApexStock.setApexCharts(ApexCharts), or leave it on window.ApexCharts as the core library expects. Under a bundler, prefer one of the first two.
Usage
import { useMemo } from 'react'
import ApexStock from 'react-apexstock'
export function PriceChart({ data }) {
// Memoize so the chart only updates when inputs actually change.
const options = useMemo(
() => ({
chart: { height: 420 },
theme: { mode: 'light' },
}),
[]
)
const series = useMemo(() => [{ name: 'Price', data }], [data])
return <ApexStock options={options} series={series} style={{ width: '100%' }} />
}
OHLC points use the ApexStock shape { x, y: [open, high, low, close], v }, see Data Format.
Props
| Prop | Type | Description |
|---|---|---|
options | StockChartOptions | Full chart options (the 2nd argument to new ApexStock). Required. |
series | StockChartOptions["series"] | Convenience: overrides options.series, handy for frequently-changing data. |
className | string | Class applied to the container element. |
style | React.CSSProperties | Inline styles applied to the container element. |
Pass stable / memoized
optionsandseries. A new object identity on every render triggers anupdate(). Keep static config inoptionsand pass changing data throughseries.
Accessing the instance
The component forwards a ref exposing an imperative handle. getInstance() returns the live ApexStock instance (call any of its methods) or null before mount; getElement() returns the container <div>.
import { useRef } from 'react'
import ApexStock, { type ApexStockRef } from 'react-apexstock'
function Toolbar({ series }) {
const ref = useRef<ApexStockRef>(null)
const addRSI = () => ref.current?.getInstance()?.updateIndicator('rsi')
return (
<>
<button onClick={addRSI}>Add RSI</button>
<ApexStock ref={ref} options={{ chart: { height: 400 }, series }} />
</>
)
}
Through the instance you can reach the full core API: indicators, trading overlays, streaming, theme switching, and export.
Server-side rendering
The component renders only a container <div> on the server; the chart is created in a client-only effect. The core apexstock package is import-safe in Node, but rendering needs a DOM. No extra guards are required in Next.js or other SSR setups.
Licensing
Register your license key once, before charts render, with the core class. See Installation & Usage.