admin管理员组文章数量:1023744
I keep getting this error from ESLint on my ponent.
ESLint: says Prefer Default Export (import/prefer-default-export)
Here's is how the ponent looks
export class myponent extends React.Component {
render() {
//stuff here
}
}
What is it asking for? How can I fix this?
I keep getting this error from ESLint on my ponent.
ESLint: says Prefer Default Export (import/prefer-default-export)
Here's is how the ponent looks
export class myponent extends React.Component {
render() {
//stuff here
}
}
What is it asking for? How can I fix this?
Share Improve this question asked Apr 16, 2017 at 22:29 user7801216user7801216 3- developer.mozilla/en/docs/web/javascript/reference/… – azium Commented Apr 16, 2017 at 22:31
- First result on google for "eslint prefer-default-export": github./benmosher/eslint-plugin-import/blob/master/docs/… – Jordan Running Commented Apr 16, 2017 at 22:32
- I've seen that but it's different to my ponent so I don't understand what I need to change on my ponent. Also, I got the ponent format code from React website itself :o/ – user7801216 Commented Apr 16, 2017 at 22:34
1 Answer
Reset to default 5you need to specify your export as default like this:
export default class myponent extends React.Component {
render() {
//stuff here
}
}
(notice the added word default
) and then in other files you may import your ponent with:
import myponent from './myponent.js';
assuming that the ponent is being included from within the same directory and is defined in the file myponent.js.
You can also avoid having a default export if your file contains multiple exported things with names such as:
export const foo = 'foo';
export const bar = 'bar';
or you could even leave your original file exactly as it is without the word default
and import it using a batch import:
import * as myponent from './myponent.js';
I keep getting this error from ESLint on my ponent.
ESLint: says Prefer Default Export (import/prefer-default-export)
Here's is how the ponent looks
export class myponent extends React.Component {
render() {
//stuff here
}
}
What is it asking for? How can I fix this?
I keep getting this error from ESLint on my ponent.
ESLint: says Prefer Default Export (import/prefer-default-export)
Here's is how the ponent looks
export class myponent extends React.Component {
render() {
//stuff here
}
}
What is it asking for? How can I fix this?
Share Improve this question asked Apr 16, 2017 at 22:29 user7801216user7801216 3- developer.mozilla/en/docs/web/javascript/reference/… – azium Commented Apr 16, 2017 at 22:31
- First result on google for "eslint prefer-default-export": github./benmosher/eslint-plugin-import/blob/master/docs/… – Jordan Running Commented Apr 16, 2017 at 22:32
- I've seen that but it's different to my ponent so I don't understand what I need to change on my ponent. Also, I got the ponent format code from React website itself :o/ – user7801216 Commented Apr 16, 2017 at 22:34
1 Answer
Reset to default 5you need to specify your export as default like this:
export default class myponent extends React.Component {
render() {
//stuff here
}
}
(notice the added word default
) and then in other files you may import your ponent with:
import myponent from './myponent.js';
assuming that the ponent is being included from within the same directory and is defined in the file myponent.js.
You can also avoid having a default export if your file contains multiple exported things with names such as:
export const foo = 'foo';
export const bar = 'bar';
or you could even leave your original file exactly as it is without the word default
and import it using a batch import:
import * as myponent from './myponent.js';
本文标签: javascriptReact Component ESLint says Prefer Default ExportStack Overflow
版权声明:本文标题:javascript - React Component ESLint says Prefer Default Export - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745530814a2154740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论