React Inspector

9.0.0 · active · verified Sun Apr 19

React Inspector is a React component that brings the power of browser DevTools object and table inspectors directly into a React application. It allows developers to visualize JavaScript objects and data structures in a hierarchical, interactive tree view or a tabular format, similar to `console.log` or `console.table`. The current stable version is `9.0.0`. The library appears to have an active development and release cadence, with several major versions released over time, indicating ongoing maintenance and feature enhancements. Its key differentiator is providing a fully customizable, in-app debugging UI that operates within the application itself, eliminating the need to constantly switch to external browser developer tools. It also features intelligent state management, such as preserving tree expansion state across re-renders, which significantly improves the debugging experience for dynamic data. This makes it a powerful tool for developing and showcasing complex data structures directly within a user interface.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic usage of <Inspector />, <ObjectInspector />, and <TableInspector /> components with sample data, showcasing their ability to display complex JavaScript objects and arrays in an interactive, formatted manner within a React application.

import React from 'react';
import { Inspector, ObjectInspector, TableInspector } from 'react-inspector';

interface AppProps {}

const sampleObject = {
  id: 1,
  name: "Alice",
  details: {
    age: 30,
    occupation: "Software Engineer",
    projects: [
      { name: "Project A", status: "completed" },
      { name: "Project B", status: "in progress", teamSize: 5 }
    ]
  },
  isActive: true,
  lastLogin: new Date()
};

const sampleArray = [
  { id: 1, name: "Item One", value: 100 },
  { id: 2, name: "Item Two", value: 200 },
  { id: 3, name: "Item Three", value: 150 }
];

const App: React.FC<AppProps> = () => {
  return (
    <div style={{ padding: '20px', fontFamily: 'monospace', backgroundColor: '#282c34', color: '#abb2bf' }}>
      <h1 style={{ color: '#61dafb' }}>React Inspector Examples</h1>

      <h2 style={{ marginTop: '30px', color: '#98c379' }}>&lt;Inspector /&gt; (shorthand)</h2>
      <p>A versatile inspector that intelligently renders objects or DOM nodes.</p>
      <div style={{ backgroundColor: '#1e2127', padding: '10px', borderRadius: '5px' }}>
        <Inspector data={sampleObject} name="sampleObject" expandLevel={2} />
      </div>

      <h2 style={{ marginTop: '40px', color: '#e5c07b' }}>&lt;ObjectInspector /&gt;</h2>
      <p>Displays a JavaScript object in a hierarchical tree view.</p>
      <div style={{ backgroundColor: '#1e2127', padding: '10px', borderRadius: '5px' }}>
        <ObjectInspector
          data={sampleObject.details}
          name="details"
          expandPaths={['$', '$.projects']}
          sortObjectKeys={true}
        />
      </div>

      <h2 style={{ marginTop: '40px', color: '#c678dd' }}>&lt;TableInspector /&gt;</h2>
      <p>Renders array or object data in a tabular format.</p>
      <div style={{ backgroundColor: '#1e2127', padding: '10px', borderRadius: '5px' }}>
        <TableInspector data={sampleArray} />
      </div>
    </div>
  );
};

export default App;

view raw JSON →