Skip to content

appthrust/react-hook-observability

Repository files navigation

react-hook-observability

About

react-hook-observability includes multiple libraries that provide Observability as React Hooks in React.

Library Name Description README NPM
@react-hook-observability/hooks Provides Observability as React Hooks in React. README npm version
@react-hook-observability/nextjs-hooks Provides Observability as React Hooks in React and this is specific to Next.js. README npm version
@react-hook-observability/nextjs-server-actions Provides ServerActions for Next.js. README npm version

Getting Started

Install the library.

npm

npm install @react-hook-observability/hooks

yarn

yarn add @react-hook-observability/hooks

pnpm

pnpm add @react-hook-observability/hooks

bun

bun add @react-hook-observability/hooks

Usage

useBrowserEventSpans + useClientConsoleExporter

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  // 1. Setup Interactor and return following properties.
  // - watchRef: <html> tag ref
  // - spans: trace spans
  // - resetSpans: reset trace spans
  const { watchRef, spans, resetSpans } = useBrowserEventSpans({
    eventKinds: ["click"],
    batchConfig: {
      scheduledDelayMillis: 100,
    },
  });
  // 2. Setup Exporter. In this case, useClientConsoleExporter.
  useClientConsoleExporter({ spans, resetSpans, intervalDuration: 100 });
  // 3. Rendering html tag with watchRef.
  return (
    <html lang="en" ref={watchRef}>
      <body className={inter.className}>{children}</body>
    </html>
  );
}

Contributing

see CONTRIBUTING.md