现象:
代码 import { OpenTradeStock } from '../../components/open-trade-stock';
中的 OpenTradeStock
处提示import/named
错误
原因:
open-trade-stock.js 文件使用了 ES5 的写法,module.exports = { OpenTradeStock }
解决:
将 open-trade-stock.js 文件改用 ES6 的写法,export = { OpenTradeStock }
Bad
_getData()
Good
getData()
Bad
const selectButton = this.state.selectButton
Good
const { selectButton } = this.state;
Bad
const item = items[0];
Good
const [item] = items;
Bad
let pagination = this.props.get_correct_stocks_list && this.props.get_correct_stocks_list.pagination || []
Good
const { get_correct_stocks_list = {} } = this.props;
const { pagination = [] } = get_correct_stocks_list;
Bad
let pagination = this.props.get_correct_stocks_list && this.props.get_correct_stocks_list.pagination || []
Good
- const { get_correct_stocks_list = {} } = this.props;
+ const { get_correct_stocks_list: stockList = {} } = this.props;
const { pagination = [] } = stockList;
Bad
constructor(props) {
super(props);
}
Good
如果是空构造函数,就需将其删除
Bad
shouldGetNextData={this.shouldGetNextData.bind(this)}
Good
shouldGetNextData = () => {};
...
shouldGetNextData={this.shouldGetNextData}
Bad
'use strict';
Good
- 将其删除,使用 ESLint
Bad
import React, { PureComponent } from "react";
import ActionCreators from "../../actions";
import { bindActionCreators } from "redux";
Good
import React, { PureComponent } from "react";
import { bindActionCreators } from "redux";
import ActionCreators from "../../actions";
Bad
import navigate from "../../utils/navigate";
Good
import navigate from '../../utils/navigate';