|
| 1 | +<p align="center"> |
| 2 | + <h1 align="center">react-hook-observability</h1> |
| 3 | +</p> |
| 4 | + |
| 5 | +## About |
| 6 | + |
| 7 | +**react-hook-observability** is a library that provides Observability as React Hooks in React. |
| 8 | + |
| 9 | +**react-hook-observability** provides the following React Hooks. |
| 10 | + |
| 11 | +| Hook Name | Description | README | |
| 12 | +| :----------------------- | :--------------------------------------- | :------------------------------------------------------------------------------- | |
| 13 | +| `useBrowserEventSpans` | Get spans when web browser event occurs. | [useBrowserEventSpans](./packages/hooks/use-browser-event-spans/README.md) | |
| 14 | +| `useClientConsoleTracer` | Get tracer in web browser console. | [useClientConsoleTracer](./packages/hooks/use-client-console-exporter/README.md) | |
| 15 | + |
| 16 | +## Getting Started |
| 17 | + |
| 18 | +Install the library. |
| 19 | + |
| 20 | +### npm |
| 21 | + |
| 22 | +```bash |
| 23 | +npm install @react-hook-observability/hooks |
| 24 | +``` |
| 25 | + |
| 26 | +### yarn |
| 27 | + |
| 28 | +```bash |
| 29 | +yarn add @react-hook-observability/hooks |
| 30 | +``` |
| 31 | + |
| 32 | +### pnpm |
| 33 | + |
| 34 | +```bash |
| 35 | +pnpm add @react-hook-observability/hooks |
| 36 | +``` |
| 37 | + |
| 38 | +### bun |
| 39 | + |
| 40 | +```bash |
| 41 | +bun add @react-hook-observability/hooks |
| 42 | +``` |
| 43 | + |
| 44 | +## Usage |
| 45 | + |
| 46 | +### useBrowserEventSpans + useClientConsoleExporter |
| 47 | + |
| 48 | +```tsx |
| 49 | +export default function RootLayout({ |
| 50 | + children, |
| 51 | +}: { |
| 52 | + children: React.ReactNode; |
| 53 | +}) { |
| 54 | + // 1. Setup Interactor and return following properties. |
| 55 | + // - watchRef: <html> tag ref |
| 56 | + // - spans: trace spans |
| 57 | + // - resetSpans: reset trace spans |
| 58 | + const { watchRef, spans, resetSpans } = useBrowserEventSpans({ |
| 59 | + eventKinds: ["click"], |
| 60 | + batchConfig: { |
| 61 | + scheduledDelayMillis: 100, |
| 62 | + }, |
| 63 | + }); |
| 64 | + // 2. Setup Exporter. In this case, useClientConsoleExporter. |
| 65 | + useClientConsoleExporter({ spans, resetSpans, intervalDuration: 100 }); |
| 66 | + // 3. Rendering html tag with watchRef. |
| 67 | + return ( |
| 68 | + <html lang="en" ref={watchRef}> |
| 69 | + <body className={inter.className}>{children}</body> |
| 70 | + </html> |
| 71 | + ); |
| 72 | +} |
| 73 | +``` |
0 commit comments