React DevTools Inline

7.0.1 · active · verified Sun Apr 19

react-devtools-inline provides a mechanism to embed the full React Developer Tools interface directly within a browser-based application, such as online code editors (e.g., CodeSandbox, StackBlitz) or debugging tools (e.g., Replay). Unlike the standalone `react-devtools` package, this package is specifically designed for integration into host environments. The current stable version is 7.0.1, though it is part of the larger React monorepo which sees frequent updates, particularly for React v19 and related tooling like `eslint-plugin-react-hooks`. A critical differentiator is its reliance on several *experimental* React APIs, necessitating the use of `react@experimental` and `react-dom@experimental` in the target application, making it unsuitable for applications running stable React releases. It exposes distinct frontend and backend APIs for setup within a main window and an iframe, respectively.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to embed React DevTools inline by setting up both the backend and frontend. It creates an iframe to host a simple React application, initializes the backend within that iframe before React loads, then initializes the frontend in the main window and renders the DevTools UI. It also shows how to use `ReactDOMClient.createRoot` for rendering the DevTools component and how to provide the `hookNamesModuleLoaderFunction`.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import { activate, initialize as initializeBackend } from 'react-devtools-inline/backend';
import { initialize as initializeFrontend } from 'react-devtools-inline/frontend';

// Create a minimal React app to run inside the iframe
const IframeApp = () => {
  const [count, setCount] = React.useState(0);
  return (
    <div>
      <h1>Hello from Iframe React App!</h1>
      <p>Count: {count}</p>
      <button onClick={() => setCount(c => c + 1)}>Increment</button>
    </div>
  );
};

const setupDevTools = () => {
  const iframe = document.createElement('iframe');
  iframe.id = 'react-app-iframe';
  iframe.style.width = '50%';
  iframe.style.height = '100%';
  iframe.sandbox = 'allow-scripts allow-same-origin';
  document.body.appendChild(iframe);

  const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  iframeDoc.open();
  iframeDoc.write('<div id="iframe-root"></div>');
  iframeDoc.close();

  const DevTools = initializeFrontend(iframe.contentWindow);

  // Render the DevTools component in the main window
  const devToolsRoot = ReactDOMClient.createRoot(document.getElementById('devtools-root'));
  devToolsRoot.render(
    <React.StrictMode>
      <DevTools
        hookNamesModuleLoaderFunction={() => import('react-devtools-inline/hookNames')}
      />
    </React.StrictMode>
  );

  // Backend setup in the iframe
  // Important: initializeBackend must be called before React loads in the iframe
  initializeBackend(iframe.contentWindow);
  // Simulate React loading in the iframe after backend is initialized
  // In a real scenario, the iframe content would load React itself
  const iframeReactRoot = ReactDOMClient.createRoot(iframeDoc.getElementById('iframe-root'));
  iframeReactRoot.render(
    <React.StrictMode>
      <IframeApp />
    </React.StrictMode>
  );

  // Activate backend once frontend is ready and React is loaded in iframe
  activate(iframe.contentWindow);
};

// Initial HTML structure
const mainRoot = document.getElementById('root');
if (mainRoot) {
  mainRoot.innerHTML = '<div id="devtools-root" style="width:50%; height: 500px; float: left;"></div>';
  setupDevTools();
}

view raw JSON →