question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

displayName is set to "o" when minifiying Stateless function components via webpack

See original GitHub issue

Given a component defined as:

export const SubmitButton = ({readyState, defaultText, pendingText}) => (
    <button
        className="btn btn-lg btn-primary btn-block"
        type="submit"
        disabled={readyState === "pending"}>
        {
            readyState === "pending"
                ? (pendingText || defaultText)
                : defaultText
        }
    </button>
);

and minified with webpack’s UglifyJsPlugin, you get components with displayName “o” in the React browser tools.

untitled

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
silvenoncommented, Dec 8, 2015

Mind blown 😮 Thanks a bunch!

For others who stumble onto this discussion:

import React from 'react';
import Foo from './Foo';

const Bar = (props) => {
  if (props.children.type === Foo) {
    // ...
  }

  return /* ... */;
};
4reactions
sophiebitscommented, Dec 8, 2015

@silvenon I wouldn’t recommend it. Why not compare the type to the object exactly?

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to set displayName in a functional component [React]
The docs for displayName say. The displayName string is used in debugging messages. Usually, you don't need to set it explicitly because it's...
Read more >
React displayName on production is minified, how to turn off?
I'm fixing this by manually setting the displayName on each component. Once I've done it for all of them, it will be easier,...
Read more >
React Basics - GitHub Pages
Webpack is a modular build tool that has two sets of functionality ... Although the Stateless component has no state, it still receives...
Read more >
babel-plugin-transform-react-stateless-component-name - npm
A babel plugin to add name for default exported stateless components.. Latest version: 1.1.2, last published: 5 years ago. Start using ...
Read more >
Learning React - Repository Institut Informatika dan Bisnis Darmajaya
Refs in Stateless Functional Components. 134. React State Management. 135. Introducing Component State. 136. Initializing State from Properties.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found