最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does React dev tools show my component as Anonymous? - Stack Overflow

programmeradmin1浏览0评论

React dev tools works perfectly (properly shows the name of the ponent in ponents tab) when you have something like:

const MyComponent = ...
export { MyComponent }

But if you change it to inline exporting:

export const MyComponent = ...

it displays the ponent name as Anonymous.

Is something wrong with inline exporting in general?

React dev tools works perfectly (properly shows the name of the ponent in ponents tab) when you have something like:

const MyComponent = ...
export { MyComponent }

But if you change it to inline exporting:

export const MyComponent = ...

it displays the ponent name as Anonymous.

Is something wrong with inline exporting in general?

Share Improve this question asked Mar 23, 2020 at 18:44 Boris ParfenenkovBoris Parfenenkov 3,2791 gold badge26 silver badges30 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

For inline exporting you need to manually specify the displayName property (I know, it's a pain).

So you do

    export const MyComponent = () => {
      //stuff happens here
    }

    MyComponent.displayName = "MyComponent";

If it's still not resolved as it wasn't for me, I found a workaround, I added -

devtool: 'eval-cheap-module-source-map'

to my webpack.config.js and make sure to start the webpack build after adding the property.

Before adding the devtool.

After adding the devtool.

source: https://webpack.js/configuration/devtool/

发布评论

评论列表(0)

  1. 暂无评论