无法读取未定义的 属性 'data'

Cannot read property 'data' of undefined

这个错误似乎在 Whosebug 上广为人知,但没有 post 给我一个适用于我的情况的解决方案。我无法在不收到错误的情况下在我的子元素中建议按钮或复选框:

Cannot read property 'data' of undefined

这个例子并不完美,因为它还没有完全重现我遇到的问题,但它已经很好地说明了我想做的事情和我做事的方式:https://codesandbox.io/s/test-uz-713xy

全球目标是显示来自 table 的配置文件并能够显示弹出窗口以根据所选配置文件修改信息

我做了 2 处更改,现在您的 codesandbox 示例运行良好。我在render中修改的地方都做了注释

     render() {
    let func = this.editChild;   // CHANGE HERE
    return (
      <div className="Profil">
        {this.state.data.map(function(panel) {
          return (
            <div className="cHildContener">
              <h1> Hello my name is {panel.name}</h1>
              <h2> I'm {panel.age} years old</h2>
              <Button
                onClick={() => {
                  func(false); // CHANGE HERE
                }}
              >
                EDIT
              </Button>
            </div>
          );
        })}
        {this.state.PopupEdit ? (
          <div className="PopUP">
            <h1>EDIT A CHILD</h1>
            <p>
              I would like display the name of the concerned child, but i don't
              know how to do
            </p>
            <input
              type="text"
              value={this.state.firstname}
              onChange={this.onFieldChange("firstname").bind(this)}
              placeholder="children new name"
              required
            />
            />
            <input
              className="slave"
              type="text"
              value={this.state.age}
              onChange={this.onFieldChange("age").bind(this)}
              placeholder="children age"
              required
            />
            <Button
              onClick={() => {
                this.editChild(true);
              }}
            >
              EDIT
            </Button>
          </div>
        ) : null}
      </div>
    );
  }