New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

app-tracking-npm-package

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-tracking-npm-package

Track and visualize Next.js components, props, and state for the SPS Canvas tool

latest
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

Next.js Component Tracker

A lightweight library that enables tracking React component state, props, and render behavior in Next.js applications for visualization in the SPS Canvas tool.

Installation

npm install --save app-tracking-npm-package
# or
yarn add app-tracking-npm-package

Usage

1. Initialize the tracker in your app

For App Router (Next.js 13+)

Add the tracker to your root layout:

// app/layout.js
'use client';

import { initTracker } from 'app-tracking-npm-package';
import { useEffect } from 'react';

export default function RootLayout({ children }) {
  useEffect(() => {
    if (typeof window !== 'undefined') {
      initTracker();
    }
  }, []);

  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}

For Pages Router

Add the tracker to your _app.js file:

// pages/_app.js
import { initTracker } from 'app-tracking-npm-package';
import { useEffect } from 'react';

function MyApp({ Component, pageProps }) {
  useEffect(() => {
    if (typeof window !== 'undefined') {
      initTracker();
    }
  }, []);

  return <Component {...pageProps} />;
}

export default MyApp;

2. Track components (Optional)

You can enhance your components with tracking capabilities using the withTracking HOC:

import { withTracking } from 'app-tracking-npm-package';

function Button({ onClick, children }) {
  return (
    <button 
      onClick={onClick}
      className="px-4 py-2 bg-blue-600 text-white rounded"
    >
      {children}
    </button>
  );
}

// Export with tracking - second parameter is the component name for the canvas
export default withTracking(Button, 'Button');

3. Track component state

Use the useTrackedState hook to automatically track state changes:

import { useTrackedState } from 'app-tracking-npm-package';

function Counter() {
  // Works just like useState but reports state changes to the Canvas
  const [count, setCount] = useTrackedState(0, 'Counter');
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

export default Counter;

Connecting to the Canvas

  • Run your Next.js app locally (e.g., npm run dev)
  • Open the SPS Canvas tool
  • Enter your local app URL (typically http://localhost:3000)
  • Click "Connect"

The Canvas will automatically:

  • Detect your components
  • Visualize the component hierarchy
  • Show real-time props and state changes
  • Track component relationships

API Reference

initTracker()

Initializes the tracker and connects to the Canvas tool when available.

withTracking(Component, displayName)

Higher-Order Component that wraps your React component to track renders and props.

  • Component: The React component to track
  • displayName: (Optional) Name to display in the Canvas (defaults to component name)

useTrackedState(initialState, componentName)

A drop-in replacement for React's useState that tracks state changes.

  • initialState: Initial state value (same as useState)
  • componentName: Name of the component using this state

trackComponent(componentName, props, state)

Low-level function to manually track component data.

  • componentName: Name of the component to track
  • props: Component props object
  • state: Component state object

Keywords

react

FAQs

Package last updated on 02 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts