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.
npm install logrocket-reactVerified import paths — ran on the pinned version, not inferred.
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.
Consult the package's README or documentation for the correct `logrocket-react` version for your React installation. E.g., `npm i --save logrocket-react@7` for React 19, `logrocket-react@6` for React 18, etc.
Manually add `Component.displayName = 'ComponentName';` to your functional components or class components, or ensure your Babel/Webpack configuration includes a plugin that sets `displayName` (e.g., `@babel/plugin-transform-react-jsx-self`).
For `logrocket-react@7` and newer, use `import LogRocketReact from 'logrocket-react'; LogRocketReact.init(LogRocket);`. Review the specific version's documentation for exact usage.
Ensure both `LogRocket` from `logrocket` and `LogRocketReact` from `logrocket-react` are imported. Call `LogRocket.init()` before `LogRocketReact.init(LogRocket)`.
Ensure all React hooks are called only from functional components or other custom hooks. This is a general React rule, but misinterpreting LogRocket's integration points could lead to it.
Upgrade all related packages, especially `react` and `logrocket-react`, to their latest compatible versions. Ensure `prop-types` is used for explicit type checking if needed for custom components.