【发布时间】:2020-07-14 18:02:04
【问题描述】:
我正在尝试编写每次用户单击按钮时进行投票的方法,它应该增加 1,它发生在下面的代码中
retro.js
export class RetroComponent extends Component {
constructor(props) {
super(props);
this.textareaRef = React.createRef();
this.state = {
value: 0
}
}
addCard(){
console.log("add card");
}
incrementWentWell() {
// eslint-disable-next-line react/no-direct-mutation-state
return ++this.state.value;
}
render() {
return (
<IconButton onClick={() => this.incrementWentWell()}>
<ThumbUpTwoToneIcon />
</IconButton>
<h5 style={{marginRight: 10}}><p>{this.state.value}</p></h5>
)}
}
【问题讨论】:
-
您专门禁用了告诉您问题所在的 ESlint 规则。 github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/…
标签: javascript reactjs increment