Skip to content

KlinechartsUIProvider

The root provider. Wrap your application (or chart subtree) in it and supply the context that every hook reads from.

import { KlinechartsUIProvider } from "react-klinecharts-ui";
<KlinechartsUIProvider
datafeed={myDatafeed}
defaultSymbol={{ ticker: "BTCUSDT", pricePrecision: 2 }}
defaultTheme="dark"
onSymbolChange={(symbol) => saveToStorage("symbol", symbol)}
>
<App />
</KlinechartsUIProvider>;
PropTypeDefaultDescription
datafeedDatafeed—Required. Datafeed interface implementation
defaultSymbolPartialSymbolInfonullInitial trading instrument
defaultPeriodTerminalPeriodFirst in periodsInitial timeframe
defaultThemestring"light"Initial theme ("light" or "dark")
defaultTimezonestring"Asia/Shanghai"Initial timezone (IANA)
defaultMainIndicatorsstring[]["MA"]Indicators on the main chart at startup
defaultSubIndicatorsstring[]["VOL"]Indicators on sub-panels at startup
defaultLocalestring"en-US"Locale passed to klinecharts
periodsTerminalPeriod[]DEFAULT_PERIODSList of available timeframes
stylesDeepPartial<Styles>—Custom klinecharts styles (applied when the chart is ready)
registerExtensionsbooleantrueWhether to register built-in drawing overlays + feature overlays (orderLine, alertLine, depthOverlay)
overlaysOverlayTemplate[]—Extra custom overlay templates. The built-in feature overlays are already auto-registered
onStateChange(action, nextState, prevState) => void—Called synchronously on every dispatched action
onSymbolChange(symbol) => void—Called when the symbol changes
onPeriodChange(period) => void—Called when the period changes
onThemeChange(theme) => void—Called when the theme changes
onTimezoneChange(timezone) => void—Called when the timezone changes
onMainIndicatorsChange(indicators: string[]) => void—Called when main indicators change
onSubIndicatorsChange(indicators: Record<string, string>) => void—Called when sub-indicators change
onSettingsChange(settings: Record<string, unknown>) => void—Called when settings change via useKlinechartsUISettings

The provider registers overlays once on mount via useRef — passing an inline array is safe and does not cause re-registration:

// Safe — does not re-register on every render
<KlinechartsUIProvider overlays={[orderLine, myCustomOverlay]}>

The on*Change callbacks make it easy to persist user preferences. They fire after the corresponding state transition:

<KlinechartsUIProvider
datafeed={datafeed}
onSymbolChange={(s) => localStorage.setItem("symbol", JSON.stringify(s))}
onPeriodChange={(p) => localStorage.setItem("period", JSON.stringify(p))}
onThemeChange={(t) => localStorage.setItem("theme", t)}
>

onStateChange is the catch-all: it runs synchronously on every dispatched action with (action, nextState, prevState), which is ideal for analytics or debugging.

See also: Datafeed · State & Actions.