【问题标题】:i dont know why click event is not firing.can anyone help me please [closed]我不知道为什么点击事件没有触发。任何人都可以帮助我[关闭]
【发布时间】:2022-01-24 15:24:16
【问题描述】:

【问题讨论】:

  • 欢迎来到 Stack Overflow!相关代码和错误消息需要包含在您的问题中作为文本,而不是作为文本图片。仅链接到屏幕截图会使人们更难帮助您。要了解有关此社区的更多信息以及我们如何为您提供帮助,请从 tour 开始并阅读 How to Ask 及其链接资源。
  • 至于问题本身...setState 是一个函数,而不是您覆盖的值。 Call the function with the new state value.

标签: reactjs react-dom


【解决方案1】:

我检查了您的代码并解决了问题:

import React, { Component } from 'react';

export default class Classcompo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      message: 'welcome visitors',
    };
  }
  changeMessage() {
    this.setState({
      message: 'ok',
    });
  }
  render() {
    return (
      <div>
        <h1>{this.state.message}</h1>
        <button onClick={() => this.changeMessage()}>CLICK</button>
      </div>
    );
  }
}

【讨论】:

    猜你喜欢
    • 2017-04-22
    • 2022-06-16
    • 2018-04-24
    • 2014-01-25
    • 1970-01-01
    • 2015-03-15
    • 2012-11-30
    • 1970-01-01
    • 2022-12-10
    相关资源
    最近更新 更多