Skip to content

@sqlrooms/vega / useVegaChartContext

Function: useVegaChartContext() ​

useVegaChartContext(): VegaChartContextValue

Hook to access the Vega chart context within action components.

Returns ​

VegaChartContextValue

Example ​

tsx
function CustomExportAction() {
  const { embed } = useVegaChartContext();

  const handleExport = async () => {
    if (!embed?.view) return;
    const canvas = await embed.view.toCanvas(2);
    // Do something with the canvas...
  };

  return <Button onClick={handleExport}>Export</Button>;
}

Throws ​

Error if used outside of VegaLiteArrowChart