Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Developer Tools says 'Proxy Component' instead of the name of the component

I am using Webpack with Hot Module Reloading. I also use the chrome extension React Developer Tools to inspect the react tree while developing. When I inspect the page and look at the component tree, I would like to see the name of the actual components, however, for every component the name shows up as Proxy Component.

I can let you know more specifics about my Webpack, but I am struggling to even google the right thing to solve this issue.

Here are the tools I am using for webpack:

"webpack": "^1.9.6",
"webpack-dev-middleware": "^1.2.0",
"webpack-dev-server": "^1.14.1",
"webpack-hot-middleware": "^2.0.0"

webpack.config.js

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-hot-middleware/client',
    './client/index'
  ],
  output: {
    path: path.join(__dirname, 'static'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: path.join(__dirname, 'client'),
        query: {
          plugins: ['transform-runtime'],
          presets: ['es2015', 'stage-0', 'react', 'react-hmre']
        }
      },
      {
        test: /\.scss$/,
        loaders: ['style', 'css', 'sass']
      }
    ]
  }
};
like image 674
fresh5447 Avatar asked May 29 '16 23:05

fresh5447


People also ask

How do you get the React component name?

To get a component's name in React, we can use the displayName property. to set the Foo. displayName property to the name we want. Then we can retrieve it in the code and the React developer tools.

How do I show components in dev tools?

Open the console by either right-clicking and inspecting an element or by opening the toolbar by clicking View > Developer > JavaScript console. The Components tab will show the current React component tree, along with any props, state, or context.

How do you define a React component?

Components are independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. Components come in two types, Class components and Function components, in this tutorial we will concentrate on Function components.

What is displayName in React?

displayName. The displayName string is used in debugging messages. Usually, you don't need to set it explicitly because it's inferred from the name of the function or class that defines the component.


2 Answers

I think it's because you should have set the node environnement variable to 'production'. In production mode, React renames your components and they are displayed as ProxyComponent in React Developer Tools.

EDIT

Your problem is with the hot module replacement and React Transform. As stated by Dan Abramov himself, when using Hot Reloading for React the components need to be proxied, and the display name of the proxied component is derivated from the displayName of your components. That's why it works when you add an explicit displayName, if you don't, React devtools will fall back to the ProxyComponent module's name : ProxyComponent.

like image 55
Pierre Criulanscy Avatar answered Oct 01 '22 03:10

Pierre Criulanscy


Have you tried to assign the displayName property?

export const Navbar = (props) => {
  let title = null;
  let menu = null;

  return (
    <header className={style.navbar}>
      <Grid>
        <Row>
          <Col xs={12} sm={12} md={12} lg={12}>
            {title}
            {menu}
          </Col>
        </Row>
      </Grid>
    </header>
  );
};

Navbar.displayName = 'Navbar'; // LIKE THIS

Navbar.propTypes = {
  title: PropTypes.string,
  items: PropTypes.arrayOf(PropTypes.node),
};
like image 26
Sergio Flores Avatar answered Oct 01 '22 03:10

Sergio Flores