How to View Redux Store Values in Production: A Complete Guide

Cijo KBCijo KB
4 min read

As React developers, we often find ourselves in a love affair with the Redux DevTools. That beautiful browser extension provides an X-ray view into our application's state, letting us track actions, inspect state changes, and even time-travel through our application's history. It's an indispensable companion during development, easily enabled by setting devtools: true in your configureStore.

But then, the application ships. It goes live. And for crucial security and performance reasons, those invaluable Redux DevTools are strictly disabled in production builds. The direct window into your store is locked.

So, what happens when you're staring at a live issue, needing to understand the very state driving a production application, and your trusty DevTools are nowhere in sight? Fear not! While you can't simply enable the Redux DevTools extension, there's a clever workaround for those times when you absolutely need to peek into the Redux store's values in a deployed application.

This guide is for every developer who's ever faced that challenge, offering a technique to understand your production Redux store's values, even when the direct view is locked away.

The Production State Detective: Using React DevTools

This method leverages the standard React DevTools, which are often not disabled in production builds (though some companies might strip them too, it's less common than stripping Redux DevTools). If your application uses React and you can inspect its components, you might be in luck!

Tools Required:

  • React DevTools browser extension (for Chrome or Firefox)

Here’s the step-by-step process:

Step 1: Open the Components Tab in React DevTools First, open your browser's developer tools (usually by pressing F12 or Ctrl+Shift+I / Cmd+Option+I). Navigate to the "Components" tab, which is part of the React DevTools extension.

Step 2: Locate a Component with the store Object in its Props In the Components tab, start clicking on various React components in the tree. As you select a component, look at the "Props" section in the right-hand panel. You're looking for a component that has a store object available in its props. This is often a top-level provider component (like a Provider from react-redux) or a component that directly consumes the Redux store.

Step 3: Access the Store State in the Console Once you've found a component with the store object in its props:

  1. Make sure that component is still selected in the React DevTools "Components" tab.

  2. Open your browser's Console tab.

  3. In the Console, type the following command:

     $r.props.store.getState()
    

    And then press Enter.

    • $r is a special variable in the Chrome DevTools console that refers to the currently selected React component in the "Components" tab.

    • .props accesses the props of that selected component.

    • .store accesses the Redux store object passed as a prop.

    • .getState() is the standard Redux method to retrieve the current state tree of the store.

You should now see the entire Redux store's state tree printed in your console! You can expand the objects to inspect the values.

Beyond just peeking at the state, what if you want to observe the actions being dispatched in real-time? While you can't use the Redux DevTools' action tab, you can temporarily 'monkey-patch' the dispatch method in the console to log actions as they occur. This provides a powerful way to understand the flow of events that modify your application's state:

// Store the original dispatch function
const originalDispatch = $r.props.store.dispatch;

// Override the dispatch function to log actions
$r.props.store.dispatch = function (...args) {
    console.log('%cRedux Action Dispatched:', 'color: #007bff; font-weight: bold;', args[0]);
    // Call the original dispatch function
    return originalDispatch.apply(this, args);
};

After running this command in the console, any action dispatched by the application will be logged to your console, giving you a live feed of state changes. Remember, this is a temporary console-side override and will reset if you refresh the page.

Important Considerations & Disclaimers:

  • Not Always Available: This method relies on the store object being exposed via props to a component that's inspectable by React DevTools. Some applications might structure their Redux integration differently or might strip React DevTools in production, making this impossible.

  • Read-Only Insight: This method provides a snapshot of the state. You cannot dispatch actions or time-travel as you would with full Redux DevTools.

  • Sensitive Data: Be mindful that if you are inspecting a live production application (especially one you don't own), you might be looking at sensitive data. Always adhere to ethical hacking principles and company policies.

  • Workaround, Not Best Practice: This is a clever workaround for emergencies, not a recommended debugging practice. For robust production monitoring, consider server-side logging, analytics, or specialized error tracking tools that capture application state securely.

While direct Redux DevTools access remains a development luxury, understanding these alternative inspection techniques can be a powerful arrow in your debugging quiver when facing the complexities of a live production environment. Happy debugging!

1
Subscribe to my newsletter

Read articles from Cijo KB directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Cijo KB
Cijo KB