[英]Why does React dev tools show my component as Anonymous?
當您有以下內容時,React 開發工具可以完美運行(在組件選項卡中正確顯示組件的名稱):
const MyComponent = ...
export { MyComponent }
但是,如果您將其更改為內聯導出:
export const MyComponent = ...
它將組件名稱顯示為匿名。
一般內聯導出有什么問題嗎?
對於內聯導出,您需要手動指定 displayName 屬性(我知道,這很痛苦)。
所以你也是
export const MyComponent = () => {
//stuff happens here
}
MyComponent.displayName = "MyComponent";
如果它仍然沒有解決,因為它不適合我,我找到了一個解決方法,我補充說 -
devtool: 'eval-cheap-module-source-map'
添加到我的webpack.config.js
並確保在添加屬性后啟動 webpack 構建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.