Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在React中呈现HtmlLevel_Html_Dom_Reactjs_Render - Fatal编程技术网

在React中呈现HtmlLevel

在React中呈现HtmlLevel,html,dom,reactjs,render,Html,Dom,Reactjs,Render,我遇到这样一个问题:我试图使用React呈现HtmlLevel,但出现以下错误: 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 createFragm

我遇到这样一个问题:我试图使用React呈现HtmlLevel,但出现以下错误:

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组件类中,我有以下代码

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>
        )
    }
}
import React,{Component}来自'React';
导出默认类VirtualList扩展组件{
建造师(道具){
超级(道具);
this.container=document.createElement('div');
}
renderList(){
让container=this.container;
//操纵容器等。
返回容器;
}
render(){
返回(
{this.renderList()}
)
}
}
非常感谢您的帮助

元素
不能与DOM元素混淆。

您可以通过React.createElement创建React元素

this.container = React.createElement('div');

您能否澄清一下为什么要使用
document.createElement
?这不是处理dom的有效方法。@AlexanderT。我编写了一些简单的javascript代码,后面有一堆逻辑,所以我想在某种意义上,将代码移植到React中,认为您可以只渲染HtmlLevel对象