npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trace-viz/react

v0.1.0

Published

React hooks and components for trace visualization

Downloads

9

Readme

@trace-viz/react

npm version

React hooks and components for trace visualization built on top of @trace-viz/core.

Features

  • React hooks for trace orchestration
  • Optimized for React 18+
  • Tree-shakeable ESM modules
  • Full TypeScript support

Installation

pnpm add @trace-viz/react react

Requirements

  • Node.js >=20
  • React ^18 || ^19
  • ESM-only (no CommonJS support)

Usage

Basic Example

import { useEffect } from 'react';
import { useTrace } from '@trace-viz/react';
import { JSONataVersionDetector } from '@trace-viz/version-detector-jsonata';

function TraceViewer({ traceData }) {
  const { state, process, restoreVisualizers } = useTrace({
    versionDetector: new JSONataVersionDetector({
      expression: 'version',
      fallback: '1',
    }),
    visualizers: [
      { version: '1', component: TraceViewerV1 },
      { version: '2', component: TraceViewerV2 },
    ],
    defaultVisualizer: { component: DefaultViewer },
  });

  useEffect(() => {
    if (traceData) {
      void process({ rawTrace: traceData });
    }
  }, [traceData, process]);

  if (state.status === 'processing') return <div>Loading...</div>;
  if (state.status === 'error') {
    return (
      <div>
        Error: {state.error?.message}{' '}
        <button onClick={restoreVisualizers}>Restore visualizers</button>
      </div>
    );
  }
  if (state.status === 'success' && state.visualizer) {
    const Visualizer = state.visualizer;
    return <Visualizer trace={state.trace} />;
  }

  return null;
}

With Initial Trace

import { useTrace } from '@trace-viz/react';
import { JSONataVersionDetector } from '@trace-viz/version-detector-jsonata';

function TraceViewer() {
  const { state } = useTrace({
    versionDetector: new JSONataVersionDetector({
      expression: 'version',
      fallback: '1',
    }),
    initialTrace: myTraceData, // Process on mount
    visualizers: [{ version: '1', component: TraceViewerV1 }],
  });

  // Trace is automatically processed on mount
  // ...
}

With Trace Preparer

import { useTrace } from '@trace-viz/react';
import { JSONataVersionDetector } from '@trace-viz/version-detector-jsonata';

function TraceViewer() {
  const { state, process } = useTrace({
    versionDetector: new JSONataVersionDetector({
      expression: 'metadata.version',
    }),
    preparer: {
      prepare: (trace, context) => ({
        ...trace,
        normalizedSpans: trace.spans.map(normalizeSpan),
      }),
    },
  });

  // ...
}

With Optional Parameters

import { useTrace } from '@trace-viz/react';

function TraceViewer({ traceData }) {
  const { process } = useTrace({
    versionDetector: new JSONataVersionDetector({ expression: 'version' }),
  });

  // Override version detection
  const handleProcessWithVersion = () => {
    process({
      rawTrace: traceData,
      overrideVersion: '2.1.0', // Use specific version
    });
  };

  // Use specific visualizer
  const handleProcessWithVisualizer = () => {
    process({
      rawTrace: traceData,
      visualizer: CustomViewer, // Bypass version detection
    });
  };

  // ...
}

Peer Dependencies

This package requires react as a peer dependency. Make sure you have React installed in your project.

API

useTrace<T>(options)

Hook options:

  • versionDetector: Version detector instance (required)
  • preparer: Optional trace preparer for transformation
  • initialTrace: Optional trace to process on mount
  • visualizers: Optional array of visualizers to register declaratively
  • defaultVisualizer: Optional fallback visualizer configuration
  • orchestratorFactory: Optional factory function to construct a custom TraceOrchestrator
  • orchestratorDependencies: Optional dependency list controlling when a new orchestrator instance is created

Returns:

  • state: Current orchestrator state ({ status, trace, version, visualizer, error })
  • process(options): Function to process trace data (returns a promise that resolves to the latest state)
    • rawTrace: Trace data to process (required)
    • overrideVersion: Optional version to use instead of detection
    • visualizer: Optional visualizer component to use instead of registry lookup
  • reset(): Function to reset state
  • registerVisualizer(options): Register visualizer for version
    • version: Version string (required)
    • component: Visualizer component (required)
  • setDefaultVisualizer(options): Set default/fallback visualizer
    • component: Visualizer component (required)
  • restoreVisualizers(): Reapply declaratively configured visualizers and default fallback
  • clearVisualizers(): Remove all registered visualizers
  • getRegisteredVersions(): Retrieve the currently registered version identifiers
  • hasVisualizer(version): Check if a visualizer or default exists for the given version
  • orchestrator: Direct access to TraceOrchestrator instance

Development

# Build
pnpm build

# Watch mode
pnpm dev

# Test
pnpm test

# Typecheck
pnpm typecheck

License

MIT