Skip to main content

Overview

The Lightdash React SDK (@lightdash/sdk) provides React components for embedding Lightdash content in your React or Next.js applications. The SDK offers advantages over iframe embedding:
  • Seamless integration with your React application
  • Programmatic filters for dashboards
  • Callbacks for user interactions (e.g., explore navigation)
  • Custom styling to match your application
  • TypeScript support with full type definitions
For iframe embedding, see the embedding reference.

Set up CORS

To use the React SDK, you need to update your “Cross-Origin Resource Sharing” (CORS) policy so the domain hosting your React app is allowed to call the Lightdash API. In Lightdash, go to Project settings -> Embed configuration -> CORS and add the origins where you will use the SDK, for example https://app.example.com or *.example.com. For self-hosted deployments, you can also configure instance-level allowed origins with environment variables:
CORS is enabled by default. Set LIGHTDASH_CORS_ENABLED=false only if you want to disable CORS for the whole instance.
Why CORS is neededEnabling CORS (Cross-Origin Resource Sharing) is necessary because browsers enforce security policies that prevent web applications from making requests to a different domain than the one that served the app (known as the Same-Origin Policy).Since the Lightdash React SDK interacts with a Lightdash API, you need to configure CORS on your Lightdash instance to allow your frontend application to communicate with the Lightdash server without being blocked by the browser.
CORS is only required for the React SDK. iframe embedding does not require CORS configuration.

Installing the Lightdash SDK

In your frontend project, use your preferred package manager to install the SDK.
At the moment, we support React 18 and 19, so make sure your frontend is using React 18 or later. For Next.js, version 15 or later is required.

Import CSS styles

The Lightdash SDK requires CSS styles to render components correctly. Import the SDK’s CSS file as the first import in your React application’s entry point:
The CSS import must be the first import in your entry file to ensure Lightdash styles load before other styles and avoid conflicts.

Components and hooks

The Lightdash SDK exports components for embedding Lightdash content and hooks for building custom host-app UI around embedded content:
  • Lightdash.Dashboard - Embed complete dashboards with multiple tiles
  • Lightdash.DashboardBuilder - Let embedded users create a brand-new dashboard
  • Lightdash.Chart - Embed individual saved charts
  • Lightdash.Explore - Embed interactive data exploration interface
  • Lightdash.AiAgent - Embed an AI agent so users can chat with their data
  • Lightdash.MetricsCatalog - Embed the project metrics catalog so users can browse and explore metrics
  • Lightdash.useLightdashContent - List spaces, dashboards, charts, and data apps for a custom content catalog
  • Lightdash.useLightdashAiAgentThreads - List an embed user’s previous AI agent threads to build a thread history UI
All components share common props for authentication and styling.

Lightdash.Dashboard

Embed complete Lightdash dashboards with multiple visualizations, filters, and interactive features.

Props

Basic usage

With filters

Apply filters programmatically using the filters prop:
See Filtering data for complete filter documentation.

With styling

With explore callback

Track when users navigate to explore:

With edit mode

When the JWT includes a writeActions claim, you can render an existing dashboard in edit mode and let users rename it, add saved charts from the allowed space, move or resize tiles, and save changes. The host app controls the edit-mode state through isEditMode and onEditModeChange.
Add-tile content is filtered to the JWT writeActions.spaceUuid, so users can only pick saved charts from the allowed space. See Write actions for the JWT claim.

Lightdash.DashboardBuilder

Let embedded users build a brand-new dashboard from scratch. On mount, the SDK creates an empty dashboard in the JWT writeActions.spaceUuid and renders it through the same embedded dashboard component as Lightdash.Dashboard. The host app controls when the dashboard is in edit mode. Use this when you want your customers to author their own dashboards inside your app — for example, a “Create dashboard” page in your customer portal — without giving them a Lightdash login.

Props

Basic usage

Requirements and behavior

  • The JWT must include a writeActions claim with spaceUuid. JWTs without writeActions fail closed for write-capable paths.
  • The new dashboard is created in writeActions.spaceUuid, named “Untitled dashboard”, and is empty.
  • Add-tile content (saved charts and SQL charts) is filtered to the same space.
  • Dashboards created or edited through the SDK are normal Lightdash dashboards — they can be viewed and edited from Lightdash and vice versa.
  • See Write actions for the JWT claim and how to configure the actor and destination space.

Lightdash.Chart

Embed individual saved charts for focused, single-metric displays with minimal UI.

Props

Unlike Dashboard, Chart does not support filters or onExplore props since charts are read-only and cannot navigate to explore.

Basic usage

With styling

Token generation for charts

Charts require a JWT with type: 'chart':
See Embedding charts guide for details.

Lightdash.Explore

Embed interactive data exploration interface with full query builder capabilities.

Props

Basic usage

With styling

Token generation for explores

Explores require canExplore: true in the JWT:

Lightdash.AiAgent

Embed a Lightdash AI agent so embedded users can chat with their data, generate charts, and save results back to a fixed space — without a Lightdash login. The component renders the agent inside an iframe. Use threadUuid to deep-link into an existing thread, or omit it to land on the new-thread screen.

Props

Lightdash.AiAgent does not accept filters, contentOverrides, or onExplore. Threads, navigation, and chart actions are managed inside the embedded agent UI.
onThreadChange fires whenever the embedded agent creates a new thread or opens an existing one. Use it together with threadUuid to persist the current conversation in your app (for example in localStorage or your own backend) and resume it the next time the user returns. Under the hood, the SDK passes a targetOrigin query parameter to the iframe and listens for lightdash:aiAgentThreadChanged postMessage events from the embedded page — no extra setup is required on your side.

Basic usage

Open a specific thread

Pass threadUuid to deep-link the embed into a specific conversation on mount:

Persist and resume the last conversation

Combine threadUuid and onThreadChange to keep users on their most recent thread across page reloads. This example stores the latest thread UUID in localStorage:

Token generation for AI agents

AI agent embeds require a JWT with content.type: 'aiAgent' and a writeActions claim that pins the destination space and the actor used for agent queries and chart saves:
See Embedding AI agents for the full guide and AI agent token for the complete JWT structure.

Lightdash.MetricsCatalog

Embed the Lightdash metrics catalog so embedded users can browse the metrics defined in a project, preview them, and — when the JWT allows it — continue into Explore without leaving your app. The component renders the catalog inside an iframe. When a viewer clicks Explore from here on a metric, the SDK swaps in an embedded Explore view; a Back action returns them to the catalog.

Props

Lightdash.MetricsCatalog does not accept filters, contentOverrides, or onExplore. The catalog and the embedded Explore it launches are managed inside the component.

Basic usage

Token generation for the metrics catalog

Metrics catalog embeds require a JWT with content.type: 'metricsCatalog' and a projectUuid. Set content.canExplore to true to let embedded users open Explore from a metric, and include a writeActions claim if you want them to save the resulting charts back to Lightdash.
Omit canExplore (or set it to false) to publish a read-only browse experience. See Embedding the metrics catalog for the full guide and Metrics catalog token for the complete JWT structure.

API hooks

Lightdash.useLightdashContent

Use useLightdashContent when you want your own app to list Lightdash content instead of embedding the Lightdash home page. A common pattern is to let customers choose a space in your UI, show the dashboards and charts in that space, then render the selected object with Lightdash.Dashboard or Lightdash.Chart. The hook calls the Lightdash content API and returns metadata only. It does not render the selected chart or dashboard, and it does not replace the chart or dashboard embed token you pass to the render component.

Backend: generate an API access token

Generate the token on your backend with your Lightdash embed secret. Never expose the embed secret in browser code.
The service account controls what the hook can list. If the service account cannot view a private space, content from that space is not returned.

Frontend: list content in a space

Options

Use the spaceUuids option as a filter, not as an authorization boundary. Authorization comes from the API access token’s service account permissions.
apiAccess tokens are for API reads such as content listing. To let embedded users save charts or dashboards, use an embed token that supports writeActions.

Lightdash.useLightdashAiAgentThreads

Use useLightdashAiAgentThreads when you want to show your users a list of their previous AI agent conversations — for example a “Recent chats” sidebar next to a Lightdash.AiAgent embed. The hook calls the AI agent threads endpoint with the embed JWT, so it returns only threads that belong to the JWT-authenticated embed user and are scoped to their embed space. Pair it with Lightdash.AiAgent’s threadUuid and onThreadChange props to let users resume any past conversation.

Options

The hook takes the same LightdashApiClientConfig as useLightdashContent, with auth.type: 'embedToken' and the AI agent embed JWT as the token.

Types

Example: thread history + resume

useLightdashAiAgentThreads uses the same embed JWT you pass to Lightdash.AiAgent. The token’s content.agentUuid and writeActions.spaceUuid are what scope the returned threads — the hook cannot list threads from a different agent or space, even if you pass a different agentUuid argument.

Generating embed tokens

All SDK components require JWTs generated server-side. Here’s a complete example:

Backend API endpoint

Frontend React component

To ensure security, JWT generation code must run in your backend, and the Lightdash embed secret must never be exposed in frontend code. This prevents unauthorized access and protects sensitive data.

Applying styles

Override styles within Lightdash components to match your application’s design.

Supported style overrides

Both properties accept normal CSS values and are set on a styles object passed to any component.

Font family

Sets the font family for all text within the embedded content. Font sizes and other properties are preserved.
Some charts and components set font-family explicitly, so the fontFamily style is applied with higher specificity to override these.

Background color

Sets the background for the embedded content. Can be any color value or 'transparent'.

Complete example

CSS class overrides

Beyond the styles prop, you can target embedded dashboard elements directly from your application’s stylesheet. Each element below carries a stable, human-readable classname that is part of the SDK’s public API — it won’t change when internal layout does, so your overrides stay resilient across releases.
ClassElement
ld-dashboard-headerThe dashboard header bar
ld-dashboard-filtersThe filter bar row
ld-dashboard-filterAn individual filter pill
ld-dashboard-date-zoomThe date-zoom control(s)
ld-dashboard-parametersThe parameters row
ld-dashboard-parameterAn individual parameter pill
ld-dashboard-filter-dropdownAn open filter’s dropdown
ld-dashboard-date-zoom-dropdownThe open date-zoom menu
ld-dashboard-parameter-dropdownAn open parameter’s dropdown
The filter, date-zoom, and parameter dropdowns render in a portal at the page root — outside the dashboard container — so target them with a global selector rather than as a descendant of the embedded dashboard.

Light and dark mode

Use the theme prop to render embedded content in either 'light' or 'dark' mode. This is typically driven by the host application’s own theme state, so the embedded dashboard, chart, or explore matches the surrounding UI.
The theme prop is supported on Lightdash.Dashboard, Lightdash.Chart, and Lightdash.Explore.
When theme is set, the SDK forces the Mantine color scheme and ignores any user-toggled preference stored in the embed. Omit the prop to let the embed use its default (light) color scheme.

Syncing with your app’s theme

Pass your app’s current theme value directly to the SDK so the embed re-renders when it changes:

Combining with styles.backgroundColor

When theme is set, the embed uses the matching Mantine body background by default. If you also pass styles.backgroundColor, your value takes precedence:

Color palettes

You can customize the appearance of embedded dashboards using color palettes. Define multiple color palettes in your organization settings, then apply them to embedded dashboards using the paletteUuid prop. For more on customizing appearance, see customizing the appearance of your project.

Setting up color palettes

  1. Go to Organization settings > Appearance in Lightdash
  2. Define one or more color palettes
  3. Copy the palette UUID for the palette you want to use (or fetch from API GET /api/v1/org/color-palettes)

Applying a palette

Pass the paletteUuid prop to the Lightdash.Dashboard component:

Filtering data

Filters can be passed to <Lightdash.Dashboard/> to filter dimensions by values. Filters are applied as AND operations, each further restricting results.
Filtering is only available for Dashboard components. Chart and Explore components do not support the filters prop.
For the filters prop to work, your JWT must have dashboardFiltersInteractivity set to enabled: 'all'. Without this configuration, filters will not be applied.

Filter structure

Basic example

Multiple filters

Filters are applied as AND operations:

FilterOperator enum

Import FilterOperator from the SDK:
Available operators:
OperatorDescriptionValue Type
FilterOperator.IS_NULLField is nulln/a
FilterOperator.NOT_NULLField is not nulln/a
FilterOperator.EQUALSField equals valuesingle value
FilterOperator.NOT_EQUALSField does not equal valuesingle value
FilterOperator.STARTS_WITHField starts with valuesingle value
FilterOperator.ENDS_WITHField ends with valuesingle value
FilterOperator.INCLUDEField includes any of valuesarray
FilterOperator.NOT_INCLUDEField does not include valuesarray
FilterOperator.LESS_THANField is less than valuesingle value
FilterOperator.LESS_THAN_OR_EQUALField is ≤ valuesingle value
FilterOperator.GREATER_THANField is greater than valuesingle value
FilterOperator.GREATER_THAN_OR_EQUALField is ≥ valuesingle value
FilterOperator.IN_THE_PASTDate in the past N unitssingle value
FilterOperator.NOT_IN_THE_PASTDate not in past N unitssingle value
FilterOperator.IN_THE_NEXTDate in the next N unitssingle value
FilterOperator.IN_THE_CURRENTDate in current periodsingle value
FilterOperator.NOT_IN_THE_CURRENTDate not in current periodsingle value
FilterOperator.IN_BETWEENField between two valuesarray with 2 values
FilterOperator.NOT_IN_BETWEENField not between valuesarray with 2 values

Available fields

Only fields that are available for filtering can be filtered. These are specified in the JWT passed to the SDK.
To generate tokens with filterable fields, configure your embed in the Lightdash UI or include the appropriate fields in your JWT structure.

Localization

The Lightdash SDK supports multilingual translation using standard i18n translation objects. To display a translated Lightdash dashboard, pass a correctly formatted translation object to the SDK.
  • Translation maps – The Lightdash CLI can generate translation maps when downloading content as code
  • Runtime translation management – Use a translation library like i18next
  • Translation production tools – Tools like Locize help manage translations efficiently

Video overview

Translation maps

The Lightdash CLI can produce translation maps for dashboards and charts. To include translation maps when downloading content, add the --language-map flag:
Alongside each downloaded dashboard and chart, there will be a <file name>.language.map.yml file containing translatable strings. Example translation map:
These translation maps can be imported into tools like Locize to begin translation.

Runtime translation

At runtime, pass a translation object to the SDK’s contentOverrides prop. We suggest using i18Next to load translations:

Setting up i18Next with Locize

What can be translated

Can be translated (UI strings specified in Lightdash):
  • Dashboard names and descriptions
  • Tile titles
  • Chart names
  • Axis labels
  • Series names
  • Markdown content
Cannot be translated (data from your warehouse):
  • String values in charts
  • Dimension values
  • Metric names from database
  • Raw data in tables
Strings originating from your data warehouse cannot be translated by the SDK. They are presented as they exist in your database.

Complete example

Here’s a full example integrating everything:

Backend (Express + Node.js)

Frontend (React)

See also

Embedding quickstart

Get started with embedding in 5 minutes

Embedding API reference

Complete JWT structure and configuration

iframe embedding reference

Complete iframe URL patterns and HTML embedding

Embedding dashboards

Complete guide to dashboard embedding

Embedding charts

Complete guide to chart embedding

User attributes

Implement row-level security with user attributes