fx-chartingDocs
Getting started

Next.js & React tips

Things worth knowing when you put the chart in an app.

Create datafeeds once

A datafeed object owns connections (sockets, caches). Create it once — at module level or with useMemo — not on every render.

js
"use client";
import { useMemo } from "react";
import { FxChart, binanceDatafeed } from "@fx-charting/pro";

export function CryptoChart() {
  const datafeed = useMemo(() => binanceDatafeed(), []);
  return <FxChart datafeed={datafeed} symbol="BTCUSDT" />;
}

Functions as props need a Client Component

Callbacks (onPlaceOrder, onReady, a datafeed…) can't be passed from a Server Component. Wrap the chart in a small file that starts with "use client", like above.

Several charts on one site

Each chart remembers its settings, drawings and layout in localStorage under persistKey (default "fx-chart"). Give charts that should not share them different keys, or persistKey={false} to not save anything.

Server rendering

The chart renders an empty frame on the server and draws in the browser, so pages stay fast and there are no hydration mismatches. Times are shown in UTC until the user picks a time zone.