Coder Social home page Coder Social logo

Comments (6)

KevinGhadyani-minted avatar KevinGhadyani-minted commented on June 5, 2024 5

It looks like facebook/react#17274 is supposed to fix this, but it doesn't because I'm still seeing this today:

Created from revision 23309eb38 on 5/18/2020.

from react-devtools-experimental.

Sawtaytoes avatar Sawtaytoes commented on June 5, 2024 5

@mateja176 Correct.

The working solution I have today is similar, but more-specific:

const propTypes = {}

const MyComponent = () => <div />

MyComponent.propTypes = propTypes

const MemoizedMyComponent = memo(MyComponent)

export default MemoizedMyComponent

This way, propTypes works properly as well.

from react-devtools-experimental.

KevinGhadyani-minted avatar KevinGhadyani-minted commented on June 5, 2024 3

It's really strange. I'm having the same issue. Because you're doing PageStatus =, it should pick that up as the display name.

I even tried doing:

PageStatus.displayName = 'PageStatus'
PageStatus.name = 'PageStatus'

Neither worked.

Something's weird about how react handles memoized functions. I think the goal here is for you to do:

const MemoizedPageStatus = memo(PageStatus)

In the past, I had to use a Babel plugin to get components wrapped by higher-order components to show up with the correct name. This was especially important when doing export default connect(...)(PageStatus). That plugin is extract-hoc:
https://github.com/quangbuule/extract-hoc

I'd prefer to not rely on a 3rd party lib. In this particular instance, I don't have this plugin loaded nor have I tested it in a few years. The point I'm saying is that I had to work around this in the past, but only when the exported name was non-existent. In this case, PageStatus is clearly defined as the function's name.

Maybe this is an issue in the React.memo function?

from react-devtools-experimental.

bvaughn avatar bvaughn commented on June 5, 2024 2

Anonymous is the fallback name that is displayed if the function has no intrinsic .name or user-supplied .displayName. Generally this means it was declared as an anonymous inline function, e.g. React.memo(props => ...).

You can "hide" them if you want, using a component filter with a "name" of "Anonymous" but it would probably be better to use a named function so they show up in the tree with meaningful names.

This isn't a DevTools bug so I'm going to close this issue.

from react-devtools-experimental.

mateja176 avatar mateja176 commented on June 5, 2024 2

It looks like facebook/react#17274 is supposed to fix this, but it doesn't because I'm still seeing this today:

Created from revision 23309eb38 on 5/18/2020.

I changed

const PageStatus = React.memo(
  function PageStatus ({
    splash, inline, loadingText, onHideError, successText: defaultSuccessText,
    style, className, propses, classes, theme, errorIcon, errorPrefix, // стилизация
    error, loading, success, // статус
  }) {
    // ...
});

to

const PageStatus = function PageStatus ({
    splash, inline, loadingText, onHideError, successText: defaultSuccessText,
    style, className, propses, classes, theme, errorIcon, errorPrefix, // стилизация
    error, loading, success, // статус
  }) {
    // ...
}

export default React.memo(PageStatus);

And the component name displayed correctly in the devtools. This is most likely relared to the following question

from react-devtools-experimental.

a-x- avatar a-x- commented on June 5, 2024

I showed the source code.

I wrapped function PageStatus (...) {...} into React.memo

it's common practice to avoid Anonymous component names in the dev tools

from react-devtools-experimental.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.