[英]React Component ESLint says Prefer Default Export
我不斷從組件上的ESLint收到此錯誤。
ESLint:說“首選默認導出”(import / prefer-default-export)
這是組件的外觀
export class mycomponent extends React.Component {
render() {
//stuff here
}
}
要求什么? 我怎樣才能解決這個問題?
您需要將導出指定為默認值,如下所示:
export default class mycomponent extends React.Component {
render() {
//stuff here
}
}
(注意添加的單詞default
),然后在其他文件中,您可以使用以下命令導入組件:
import mycomponent from './mycomponent.js';
假設該組件是從同一目錄中包含的,並且在文件mycomponent.js中定義。
如果文件包含多個具有以下名稱的導出內容,則還可以避免默認導出:
export const foo = 'foo';
export const bar = 'bar';
或者您甚至可以完全保留原始文件,不帶default
一詞,然后使用批量導入將其導入:
import * as mycomponent from './mycomponent.js';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.