Inside the render method of react, I am trying to render some children on the basis of state variable. Quoted below is the piece of code for the same:
render: ->
if @state.edit
@adminForm()
else
@adminRow()
if @state.showModal
React.createElement AdminDeleteModal, email: @props.admin.email, handleOK: @handleDelete, handleCancelDelete: @hidePopUpModal
This is leading me to an error: "Uncaught Invariant Violation: ReactCompositeComponent.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object."
But, when I shift this rendering part of the AdminDeleteModal
to the end of the @adminRow() method it works:
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
Although, this gives rise to another problem of having div inside tr, leading to the following warning:
Warning: validateDOMNesting(...): <div> cannot appear as a child of <tr>. See (unknown) > tr > (unknown) > div.
UPDATE: Updated the code with the suggestions below
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