Ruby on rails 4 未捕获不变冲突:ReactCompositeComponent.render():必须返回有效的ReactComponent
在react的render方法中,我试图根据状态变量呈现一些子对象。下面引用的是相同的代码:Ruby on rails 4 未捕获不变冲突:ReactCompositeComponent.render():必须返回有效的ReactComponent,ruby-on-rails-4,coffeescript,react-rails,Ruby On Rails 4,Coffeescript,React Rails,在react的render方法中,我试图根据状态变量呈现一些子对象。下面引用的是相同的代码: render: -> if @state.edit @adminForm() else @adminRow() if @state.showModal React.createElement AdminDeleteModal, email: @props.admin.email, handleOK: @handleDelete, ha
render: ->
if @state.edit
@adminForm()
else
@adminRow()
if @state.showModal
React.createElement AdminDeleteModal, email: @props.admin.email, handleOK: @handleDelete, handleCancelDelete: @hidePopUpModal
这导致我出现错误:“未捕获不变冲突:ReactCompositeComponent.render():必须返回有效的ReactComponent。您可能返回了未定义的、数组或其他一些无效对象。”
但是,当我将AdminDeleteModal
的这个呈现部分移到@adminRow()方法的末尾时,它可以工作:
adminRow: ->
dom.tr
className: 'row'
dom.td
className: "col-md-6"
@props.admin.email
dom.td
className: "col-md-6 text-right"
dom.a
className: 'glyphicon glyphicon-edit text-primary'
onClick: @handleToggle
dom.a
className: 'glyphicon glyphicon-trash text-danger deletethis'
data: { title: 'Delete Admin?' ,confirm: "Are you sure you want to delete User #{@props.admin.email}?"}
onClick: @showPopUpModal
if @state.showModal
React.createElement AdminDeleteModal, email: @props.admin.email, handleOK: @handleDelete, handleCancelDelete: @hidePopUpModal
尽管如此,这会导致另一个问题,即tr内有div,从而导致以下警告:
Warning: validateDOMNesting(...): <div> cannot appear as a child of <tr>. See (unknown) > tr > (unknown) > div.
您还需要
在tr
notdiv
中插入一个
,将div放入td
中是的,该操作没有错误,coffeescript中存在缩进问题。但是如何进行第一步呢?我经常遇到这样的问题。看起来您只是返回了一个tr
,没有正确的父元素。我错了吗?看来你是对的,我添加了tr+td作为家长。但是,它对我来说仍然不起作用。tr
的父项是什么?它是tbody
还是table
?
render: ->
if @state.edit
@adminForm()
else
@adminRow()
if @state.showModal
dom.tr null,
dom.td null,
React.createElement AdminDeleteModal, email: @props.admin.email, handleOK: @handleDelete, handleCancelDelete: @hidePopUpModal