Registry / observability / logrocket-react

logrocket-react

JSON →
library7.0.0jsnpmunverified

LogRocket React Plugin (`logrocket-react`) is an optional add-on package designed to integrate LogRocket's session replay and monitoring capabilities specifically with React applications. It allows developers to search for user sessions based on interactions with specific React components within their app. The package is currently at version 7.0.0, supporting React 19. It maintains a distinct versioning scheme tied directly to major React versions, requiring users to install a specific `logrocket-react` version corresponding to their React installation (e.g., `v7` for React 19, `v6` for React 18). This tight coupling dictates its release cadence, typically aligning with new React major releases. A key differentiator is its reliance on the `displayName` property of React components for reporting component names, which often requires specific build tooling or manual intervention.

observabilityweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Main export for initializing the React plugin. The package primarily uses ES modules. Ensure LogRocket (core) is imported and initialized first.

import LogRocketReact from 'logrocket-react';

An alternative or older named export for initialization, though `LogRocketReact.init(LogRocket)` is the current recommended pattern for v7. Use this only if specifically documented for a legacy setup.

import { setupLogRocketReact } from 'logrocket-react';

While not from `logrocket-react` directly, `LogRocket` from the core `logrocket` package is an essential dependency that must be imported and initialized *before* `logrocket-react`.

import LogRocket from 'logrocket';

This quickstart demonstrates how to initialize LogRocket and its React plugin, then render a simple React component that explicitly sets its `displayName` property, which is crucial for LogRocket's component tracking feature. It also shows how to manually track an event.

import React from 'react'; import ReactDOM from 'react-dom/client'; import LogRocket from 'logrocket'; import LogRocketReact from 'logrocket-react'; // Initialize LogRocket core first LogRocket.init(process.env.LOGROCKET_APP_ID ?? 'YOUR_APP_ID/YOUR_PROJECT_ID'); // Then initialize the React plugin LogRocketReact.init(LogRocket); interface ButtonProps { onClick: () => void; children: React.ReactNode; } // Ensure displayName is set for LogRocket to identify components const MyButton = ({ onClick, children }: ButtonProps) => { return ( <button onClick={onClick} style={{ padding: '10px 20px', cursor: 'pointer' }}> {children} </button> ); }; MyButton.displayName = 'MyInteractiveButton'; // Critical for LogRocket component tracking const App = () => { const handleClick = () => { console.log('Button clicked!'); LogRocket.track('UserClickedMyButton', { buttonName: 'MyInteractiveButton' }); }; return ( <div> <h1>LogRocket React Integration</h1> <p>This button interaction will be tracked by LogRocket.</p> <MyButton onClick={handleClick}>Click Me</MyButton> </div> ); }; const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render( <React.StrictMode> <App /> </React.StrictMode> );
Debug
Known footguns
breakingMajor versions of `logrocket-react` are tightly coupled to specific major versions of React. Installing the wrong version will lead to runtime errors or unexpected behavior.
gotchaComponent names are not reported to LogRocket unless the `displayName` property is explicitly set on your React components, or your build tooling (e.g., Babel plugins) automatically adds it.
breakingThe `init` function signature and export pattern have changed across major versions. Older versions might have used named exports like `setupLogRocketReact` or different parameters.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources