我不断从我的组件上的 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
),然后在其他文件中您可以使用以下方式导入组件:
从'./mycomponent.js'导入mycomponent;
假设该组件包含在同一目录中,并在文件 mycomponent.js 中定义。
如果您的文件包含多个导出的内容,其名称如下:
export const foo = 'foo';
export const bar = 'bar';
或者您甚至可以完全保留原始文件,不使用 default
一词,然后使用批量导入来导入它:
从'./mycomponent.js'导入*作为mycomponent;
关于javascript - React 组件 ESLint 表示更喜欢默认导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43442826/