我在尝试使用 React 呈现 HTMLDivElement 时遇到了这个问题,但是我收到以下错误:
Uncaught Invariant Violation: Objects are not valid as a React child (found: [object HTMLDivElement]). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `VirtualList`
在我的 React Component 类中,我有这段代码......
import React, { Component } from 'react';
export default class VirtualList extends Component {
constructor(props) {
super(props);
this.container = document.createElement('div');
}
renderList() {
let container = this.container;
// Manipulate container etc.
return container;
}
render() {
return (
<div>
{this.renderList()}
</div>
)
}
}
帮助将不胜感激!
最佳答案
ReactElements
不要与 DOM 元素混淆。
你可以通过 React.createElement 创建 React Element。
this.container = React.createElement('div');
关于html - 在 React 中渲染 HTMLDivElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765428/