使用 react app ++ 运算符添加增量计数器不起作用

add a incremental counter using react app ++ operators not working

我正在尝试编写每次用户单击按钮时投票的方法,它应该递增 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>
    )}
    }

仍然算作状态突变(巨大的反模式!)。忽略警告不会改变行为。使用功能状态更新获取现有状态值,向其添加 1,然后 return 一个新的状态对象,以便 React 可以协调更改并更新 UI/DOM.

incrementWentWell() {
  this.setState(state => ({ value: state.value + 1 })
}