If you build React apps, you know users break things in ways you never expect. Local debugging works… until it doesn’t. Logs only tell half the story. You want to see what really happened—without playing detective for hours. If that sounds familiar, this guide’s for you.
Here’s how to use LogRocket to actually find and fix React errors, not just stare at another dashboard.
Why bother with LogRocket?
Let’s be honest: most error monitoring tools spit out a flood of cryptic logs, random stack traces, and “uncaught exceptions” that don’t help you fix anything. LogRocket does one thing differently—it shows you what the user did before things broke. You get a replay of the session, plus all the technical details.
Who should care? - React devs tired of “Can’t reproduce” bug tickets - Teams who want fewer back-and-forths with QA - Anyone who likes catching real bugs (not just random console noise)
If you just want pretty charts, LogRocket isn’t worth it. But if you care about getting to the bottom of errors—this is for you.
Step 1: Set up LogRocket in your React app
You don’t need to overhaul your stack. The setup is straightforward, but there are a few things worth knowing.
1.1. Create a LogRocket account
- Sign up at LogRocket’s website. The free tier is enough to get started.
- Create a new “project”—think of this as one app or environment.
1.2. Install the LogRocket package
In your React project’s root, run:
bash npm install --save logrocket
or, if you use Yarn: bash yarn add logrocket
1.3. Initialize LogRocket early
You want LogRocket running as soon as possible, but not in every environment.
Add this to your main entry file (usually index.js
or App.js
):
js import LogRocket from 'logrocket';
if (process.env.NODE_ENV === "production") { LogRocket.init('your-app-id/project'); }
- Replace
'your-app-id/project'
with the code you get from LogRocket. - Only initialize it in production—no need to log your local dev weirdness.
Pro tip: Don’t put your LogRocket key in public repos. It’s not a security risk, but it’s sloppy.
Step 2: Catch and track React errors
Now for the real reason you’re here: actually seeing errors as users hit them.
2.1. Uncaught errors and exceptions
LogRocket will automatically capture unhandled exceptions and errors, including those from React’s error boundaries.
But to get the most out of it, use your own error boundaries:
js class ErrorBoundary extends React.Component { componentDidCatch(error, info) { // Send to LogRocket LogRocket.captureException(error, { extra: info }); } render() { // ...your fallback UI } }
- Wrap components where things are likely to break.
- This gives you stack traces, React component trees, and the session replay.
Don’t go overboard: You don’t need an error boundary around every button. Use them for big sections or the whole app.
2.2. Custom error reporting
Sometimes, you catch errors yourself (API failures, etc.) but still want to track them.
js try { // risky code } catch (err) { LogRocket.captureException(err); // handle gracefully }
- Use this for anything that fails silently or is swallowed by a promise.
Step 3: Filter the noise—what you should (and shouldn’t) track
LogRocket will record a lot out of the box: clicks, inputs, network requests, even console logs. That’s both a blessing and a curse.
3.1. Ignore sensitive data
LogRocket tries to mask sensitive fields, but don’t rely on it blindly. You’re responsible for not leaking user info.
js LogRocket.getSessionURL(function(sessionURL) { // Send this to your backend, not to users });
If your app has passwords, health data, or anything private: - Use their privacy configuration to mask fields. - Don’t log entire payloads if you don’t have to.
3.2. Don’t drown in noise
Not every warning or console log is worth tracking.
- Adjust LogRocket’s settings to ignore noisy logs.
- Use
LogRocket.log
,LogRocket.warn
, orLogRocket.error
for things that really matter.
Example: js if (importantThingFailed) { LogRocket.error('User could not save important thing', { details }); }
Step 4: Actually debugging errors with LogRocket
Here’s where LogRocket earns its keep: you can watch a recording of exactly what happened before an error.
4.1. Find the error session
- In LogRocket’s dashboard, errors are grouped. Click on one to see the sessions where it happened.
- You’ll get a timeline of user actions, network requests, state changes, and the actual React component tree at the time of the crash.
4.2. Session replay: what matters
You can scrub through the user’s session like a DVR: - See where they clicked, what they typed, and what network calls fired. - Pause when the error pops up—check the state, props, and last events.
This is way faster than sifting through logs and asking users “What did you do?”
But: Don’t waste time watching every session. Use the error summary to focus on the weird or recurring bugs.
4.3. Debugging React-specific bugs
You get: - The actual stack trace, with source-mapped lines (if you set up source maps) - The state of your React components - The Redux store, if you use it (with the LogRocket Redux plugin)
This is where LogRocket beats most generic log tools. You see what your app thought was happening when it crashed, not just what the browser says.
Step 5: Go beyond errors—use LogRocket for real-world insights
Errors are just the start. LogRocket can show you:
- Rage clicks: where users hammer a button out of frustration
- Network request failures
- Performance issues (slow renders, janky UI)
But be careful: it’s easy to fall down the “let’s track everything” rabbit hole.
Focus on what you actually care about: - Major bugs that block users - Slow or broken flows - Patterns you can fix (not random one-offs)
Don’t try to optimize every console warning. Nobody’s got time for that.
What LogRocket can’t do (and what to ignore)
- It won’t magically fix your code. You still have to debug, but you’ll have the context you need.
- Session replay isn’t perfect. Sometimes, weird browser extensions or ad blockers mess with recording.
- Privacy is on you. Double-check that you’re not capturing info you shouldn’t be.
- Don’t use it in dev or test environments. You’ll pollute your data with fake errors.
Skip the fancy analytics dashboards unless you’re actually going to use them. Most teams just need error tracking and session replay.
Wrapping up: Keep it simple, ship fixes faster
If you want to spend less time guessing what broke and more time fixing real bugs, LogRocket’s worth a shot. Don’t get bogged down in every feature—set it up, watch a few real user sessions, and focus on the errors that actually matter.
Start small. Iterate. The more you use it, the more you’ll figure out what you need to track—and what you can safely ignore.
Happy debugging.