JSPM

react-component-usage-visualizer

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q39392F
  • License MIT

A developer tool React component/hook that analyzes usage of your components in React.js and React Native apps dynamically (DEV only), displaying a live overlay with component render analytics, prop changes, hook activity, and unused component detection.

Package Exports

  • react-component-usage-visualizer
  • react-component-usage-visualizer/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-component-usage-visualizer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-component-usage-visualizer

A developer-focused React utility to visualize LIVE component usage, render reasons, prop/hook changes, and unused component alertsβ€”all inside a real running app overlay panel. Works with both React.js and React Native.

πŸš€ Features

  • πŸ”Ž Live overlay panel: See in-app analytics and visualize component usage, renders, and prop change frequency
  • πŸ’‘ Render reason inspector: Know why a component was re-rendered (prop, context, state)
  • πŸ”— Dependency/children graph: Show parent-child render chain as interactive tree
  • 🧩 Hook activity tracker: Track which hooks activate and how often
  • ⚠️ Unused/imported-but-inactive detector: Alert if a component never gets rendered
  • 🎨 Heatmap/graph panel: Visualize component usage by route, frequency, or page
  • πŸ“Š Performance metrics: Get insights into render efficiency and optimization opportunities
  • πŸ“€ Export functionality: Export analytics data as JSON or CSV for further analysis
  • πŸ“± React Native support: Full compatibility with React Native apps
  • πŸ”„ Platform detection: Automatically detects and adapts to React.js or React Native

🎯 Why is it unique?

Existing solutions just show profiler graphs or component hierarchies (React DevTools, Storybook Docs), but NONE combine this overlay approach with per-render prop/hook analytics in a real running instance β€” especially not as a plug-and-play npm package for easy drop-in usage.

πŸ“¦ Installation

npm install react-component-usage-visualizer

πŸš€ Quick Start

import React from 'react';
import { UsageDashboard, useComponentUsage } from 'react-component-usage-visualizer';

function MyApp() {
  useComponentUsage('MyApp'); // Track this component
  
  return (
    <>
      <UsageDashboard /> {/* Toggle overlay inside your dev app */}
      {/* Your app content */}
    </>
  );
}

πŸ“– Usage Examples

Basic Component Tracking

import { useComponentUsage } from 'react-component-usage-visualizer';

function MyComponent({ title, count }) {
  useComponentUsage('MyComponent'); // Track renders and prop changes
  
  return <div>{title}: {count}</div>;
}

Advanced Hook Tracking

import { 
  useComponentUsage, 
  useEffectTracker, 
  useMemoTracker 
} from 'react-component-usage-visualizer';

function AdvancedComponent({ data, multiplier }) {
  useComponentUsage('AdvancedComponent');
  
  // Track specific hook usage
  useEffectTracker([data, multiplier]);
  useMemoTracker([data]);
  
  const expensiveValue = useMemo(() => {
    return data.reduce((acc, item) => acc + item.value * multiplier, 0);
  }, [data, multiplier]);
  
  return <div>Result: {expensiveValue}</div>;
}

Dashboard Integration

React.js

import { UsageDashboard } from 'react-component-usage-visualizer';

function App() {
  return (
    <div>
      <h1>My React App</h1>
      {/* Your components */}
      
      {/* Add the dashboard - shows floating button in dev mode */}
      <UsageDashboard />
    </div>
  );
}

React Native

import React from 'react';
import { View } from 'react-native';
import { UsageDashboard } from 'react-component-usage-visualizer';

function App() {
  return (
    <View style={{ flex: 1 }}>
      {/* Your React Native components */}
      
      {/* Add the dashboard - shows floating button in dev mode */}
      <UsageDashboard />
    </View>
  );
}

πŸ› οΈ API Reference

Hooks

useComponentUsage(componentName)

Tracks component renders, prop changes, and provides analytics data.

Parameters:

  • componentName (string): Name to identify the component in analytics

Returns:

  • analytics: Object containing render count, prop changes, and timing data
  • trackHookActivity: Function to manually track hook usage
  • getUsageData: Function to get current usage data
  • getHookActivity: Function to get hook activity data

useEffectTracker(dependencies)

Tracks useEffect hook usage with dependencies.

useMemoTracker(dependencies)

Tracks useMemo hook usage with dependencies.

useStateTracker()

Tracks useState hook usage.

Components

<UsageDashboard />

Renders the overlay analytics panel with:

  • Overview tab: Performance metrics and component usage
  • Heatmap tab: Visual render intensity heatmap
  • Issues tab: Performance warnings and optimization suggestions
  • Export functionality: Download data as JSON or CSV (web) / Share data (React Native)

Platform-specific behavior:

  • React.js: Shows as floating overlay with file download
  • React Native: Shows as modal with native sharing

Utilities

getGlobalUsageData()

Returns all collected usage data across all components.

clearUsageData()

Clears all collected usage data (useful for testing).

exportUsageData(data, format)

Exports usage data in specified format ('json' or 'csv').

Platform Utilities

getPlatform()

Returns the current platform: 'web', 'react-native', or 'unknown'.

isReactNative()

Returns true if running in React Native environment.

isWeb()

Returns true if running in web browser environment.

getExportMethod()

Returns the export method for the current platform: 'download' (web) or 'console' (React Native).

🎨 Dashboard Features

Overview Tab

  • Total components tracked
  • Total renders across all components
  • Average renders per component
  • Most/least rendered components
  • Individual component render counts

Heatmap Tab

  • Visual intensity map of component render frequency
  • Color-coded bars showing render intensity
  • Quick identification of performance hotspots

Issues Tab

  • High render count warnings
  • Inefficient render patterns
  • Unused component detection
  • Performance optimization suggestions

πŸ”§ Advanced Configuration

Custom Analytics

import { getGlobalUsageData, exportUsageData } from 'react-component-usage-visualizer';

// Get all usage data
const allData = getGlobalUsageData();

// Export as JSON
const jsonData = exportUsageData(allData.components, 'json');

// Export as CSV
const csvData = exportUsageData(allData.components, 'csv');

Performance Monitoring

import { detectPerformanceIssues } from 'react-component-usage-visualizer';

// Check for performance issues
const issues = detectPerformanceIssues(usageData);
console.log('Performance issues:', issues);

🚨 Development Mode Only

This package is designed for development use only. The dashboard and tracking features should not be included in production builds. Consider using environment checks:

import { UsageDashboard } from 'react-component-usage-visualizer';

function App() {
  return (
    <div>
      {/* Your app */}
      {process.env.NODE_ENV === 'development' && <UsageDashboard />}
    </div>
  );
}

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

Inspired by React DevTools and the need for better component performance visualization in development environments.