【问题标题】:react-grid layout: Warning Can't call setState on a component that is not yet mountedreact-grid 布局:警告无法在尚未安装的组件上调用 setState
【发布时间】:2021-09-17 01:54:06
【问题描述】:

我想要做的是,有多个按钮来创建不同的元素。 标题是我运行应用程序时出现在控制台中的错误消息。

这是我的代码框link,它显示了代码和错误。点击链接打开控制台,出现错误

创建图表函数

 onChartItem() {
    /*eslint no-console: 0*/
    console.log("adding", "n" + this.state.newCounter);
    this.setState({
      // Add a new item. It must have a unique key!
      charts: this.state.charts.concat({
        i: "n" + this.state.newCounter,
        x: (this.state.charts.length * 2) % (this.state.cols || 12),
        y: Infinity, // puts it at the bottom
        w: 8,
        h: 6
      }),
      // Increment the counter to ensure key is always unique.
      newCounter: this.state.newCounter + 1
    });
  }

感谢任何建议

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    我把this.onChartItem = this.onChartItem(this);改成这个this.onChartItem = this.onChartItem.bind(this);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 2019-01-26
      • 2018-11-03
      • 2016-10-01
      • 2016-02-22
      相关资源
      最近更新 更多