Using LogRocket with server-side rendering

If you are using LogRocket with a server-side rendering framework, like Next.js, be sure to initialize LogRocket (and any plugins you are using) on the client and not on the server.

Example with Next.js

// you can import these packages anywhere
const LogRocket = require('logrocket');
const setupLogRocketReact = require('logrocket-react');

// only initialize when in the browser
if (typeof window !== 'undefined') {
  // plugins should also only be initialized when in the browser

Other options

If the framework you are using does not have an API for determining whether or not you are running on the browser, you can also use React's componentDidMount lifecycle method, preferably on the main app component.