Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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
Javascript react subrender函数是否必须仅返回一个外部标记中的内容?_Javascript_Reactjs - Fatal编程技术网

Javascript react subrender函数是否必须仅返回一个外部标记中的内容?

Javascript react subrender函数是否必须仅返回一个外部标记中的内容?,javascript,reactjs,Javascript,Reactjs,我有一些从主react render调用的子渲染函数: renderDueDateCell(){ if(this.props.DueDate != null){ return( <div> { this.props.DueDate } <i className="icon-shield-notice text-danger ml-5"></i>

我有一些从主react render调用的子渲染函数:

renderDueDateCell(){
    if(this.props.DueDate != null){
        return(
            <div>
                { this.props.DueDate }
                <i className="icon-shield-notice text-danger ml-5"></i>
            </div>
        )
    }
    return null
}
renderDueDateCell(){
if(this.props.DueDate!=null){
返回(
{this.props.DueDate}
)
}
返回空
}
在我删除外部div之前,它可以正常工作,而我不需要外部div。然后我去语法错误,我不能处理。这与必须有一个最外部的标记(在我的例子中是这个div)有关吗?

您可以使用
Fragment

renderDueDateCell(){
    if(this.props.DueDate != null){
        return(
            <>
                { this.props.DueDate }
                <i className="icon-shield-notice text-danger ml-5"></i>
            </>
        )
    }
    return null
}
renderDueDateCell(){
if(this.props.DueDate!=null){
返回(
{this.props.DueDate}
)
}
返回空
}
注:-