[英]Why does React dev tools show my component as Anonymous?
React dev tools works perfectly (properly shows the name of the component in components tab) when you have something like:当您有以下内容时,React 开发工具可以完美运行(在组件选项卡中正确显示组件的名称):
const MyComponent = ...
export { MyComponent }
But if you change it to inline exporting:但是,如果您将其更改为内联导出:
export const MyComponent = ...
it displays the component name as Anonymous.它将组件名称显示为匿名。
Is something wrong with inline exporting in general?一般内联导出有什么问题吗?
For inline exporting you need to manually specify the displayName property (I know, it's a pain).对于内联导出,您需要手动指定 displayName 属性(我知道,这很痛苦)。
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.添加到我的webpack.config.js
并确保在添加属性后启动 webpack 构建。
Before adding the devtool.在添加 devtool 之前。
After adding the devtool.添加开发工具后。
source: https://webpack.js.org/configuration/devtool/来源: https : //webpack.js.org/configuration/devtool/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.