最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Component ESLint says Prefer Default Export - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5

you 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';

发布评论

评论列表(0)

  1. 暂无评论