Javascript react subrender函数是否必须仅返回一个外部标记中的内容?
我有一些从主react render调用的子渲染函数: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>
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}
)
}
返回空
}
注:-