React:使用React.createElement时的appendChild替代

时间:2020-09-19 20:09:16

标签: reactjs

this.cliponSwatchesContainer.current.append(
          React.createElement(
            'button',
            {
              id: colorSwatches[cliponSwatch],
              className: this.state.swatchClassName,
              onClick: (e) => this.setFrame(e, colorSwatches),
              ref: this.swatch,
            },
            React.createElement(
              'img',
              { src: this.state.swatchImgSrc, alt: this.state.swatchImgAlt },
              null
            )
          )
        );

我正在尝试将document.createElement转换为React.createElement。当我使用appendChild()时,出现以下错误:

未捕获的TypeError:无法在“节点”上执行“ appendChild”:参数1的类型不是“节点”。

因此,我尝试使用append(),错误消失了,但是现在UI显示:

[对象对象] [对象对象]

0 个答案:

没有答案