Power BI React Component

2.0.2 · active · verified Sun Apr 19

This library provides a React wrapper for the underlying `powerbi-client` JavaScript library, enabling seamless integration of various Power BI artifacts—reports, dashboards, tiles, visuals, Q&A, and paginated reports—directly within React applications. It also facilitates the creation of new Power BI reports within the application context. The current stable version is 2.0.2, with recent major updates like v2.0.0 upgrading the peer dependency to React 18, which introduced breaking changes for older React environments. Release cadence is driven by feature additions, bug fixes, and compatibility updates, without a strict schedule but maintaining active development. Its key differentiators include a declarative, component-based API that simplifies embedding compared to direct `powerbi-client` usage, built-in lifecycle management, and support for advanced features like report bootstrapping for performance optimization and dynamic configuration updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to embed a Power BI report into a React component, including basic configuration, event handling, and accessing the embedded component reference. It uses environment variables for secure access.

import { PowerBIEmbed } from 'powerbi-client-react';
import * as models from 'powerbi-client';

function MyPowerBIReport() {
  const reportId = process.env.POWERBI_REPORT_ID ?? '';
  const embedUrl = process.env.POWERBI_EMBED_URL ?? '';
  const accessToken = process.env.POWERBI_ACCESS_TOKEN ?? '';

  if (!reportId || !embedUrl || !accessToken) {
    return <p>Please configure Power BI environment variables.</p>;
  }

  return (
    <div style={{ height: '600px', width: '100%' }}>
      <PowerBIEmbed
        embedConfig={{
          type: 'report',
          id: reportId,
          embedUrl: embedUrl,
          accessToken: accessToken,
          tokenType: models.TokenType.Embed,
          settings: {
            panes: {
              filters: {
                expanded: false,
                visible: false
              }
            },
            background: models.BackgroundType.Transparent
          }
        }}
        eventHandlers={
          new Map([
            ['loaded', () => console.log('Report loaded')],
            ['rendered', () => console.log('Report rendered')],
            ['error', (event) => console.error('Power BI error:', event.detail)],
            ['pageChanged', (event) => console.log('Page changed:', event.detail)]
          ])
        }
        cssClassName="my-powerbi-report"
        getEmbeddedComponent={(embeddedReport) => {
          console.log('Embedded component reference:', embeddedReport);
          // You can store this reference to interact with the report later
        }}
      />
    </div>
  );
}

export default MyPowerBIReport;

view raw JSON →