reactjs - 第 2 阶段 ecmaScript,在类内部解构时出现意外标记
问题描述
使用 stage 2 es 我有一个带有 prop.contest 与此 PropType 匹配的 React 组件
ContestPreview.propTypes = {
contest: PropTypes.shape({
id: PropTypes.number,
categoryName: PropTypes.string,
contestName: PropTypes.string,
}).isRequired,
};
组件是:
class ContestPreview extends React.Component {
{ contest } = this.props;
{ contestName, categoryName } = contest;
handleClick = () => {
console.log(contestName);
};
render() {
return (
<div className="link ContestPreview" role="button" onClick={this.handleClick}>
<div className="category-name">
{categoryName}
</div>
<div className="contest-name">
{contestName}
</div>
</div>
);
}
}
问题是我从 eslint 收到一个错误,unexpected token
它指向我的破坏分配的开头 {。在 ES6 中,我很乐意在其中创建构造函数并设置我的属性。这对于stage2的当前状态是否正常?我可以解决这个问题
contest = this.props.contest;
this.contest.categoryName
而是引用。但是我的 eslinting 规则确实抱怨react/destructuring-assignment代码运行良好。我只使用第 2 阶段,因为我正在做的 Lynda.com 课程正在使用它。
我的问题是,让解构工作的最佳方法是什么?目前不确定如果我更改了项目配置,我将如何将内容修改回 es6。
解决方案
推荐阅读
- excel - 多个单元宏代码的总和
- 6502 - 6502初学者问题:进位标志在哪里?
- python - pandas / Python 3中的统计列比较
- reactjs - 在服务器端渲染期间反应情感主题不起作用
- python - NEO4J 底层套接字连接消失 (_ssl.c:2084)
- salesforce - 创建 QuoteLineItems 时缺少 PriceBookEntry 必填字段
- build - 当使用样板反应时,当我更改代码时程序不会自动加载
- arrays - 有没有办法对数组中的所有给定键求和?JS
- java - 使用来自用户输入的变量的方程
- c++ - 在c ++中运行powershell脚本时如何隐藏按任意键继续