组件之一下面是我的代码收到错误:“一个有效的做出反应元素(或空)必须返回”错误与ReactJS
render() {
const mainSection = (
<MainSection
title={ __('main.section.title') }
onClose={ this.handleOnClose }
/>
);
const secondarySection = (
{
this.state.error ? (
<Message
onClose={ this.handleMessageClose }
style={ styles.message }
>
{ this.state.error }
</Message>
) : null
}
<div>
<SecondaryForm
data={ {
username: this.state.username,
} }
onChangeUsername={ this.handleUsernameChange }
onSaveUsername={ this.handleSaveUserName }
/>
</div>
);
return (
this.state.show.section === true ? { secondarySection } : { mainSection }
);
}
我得到这个错误:
A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
请帮我这个,谢谢。
我仍然得到同样的错误 – Anna
它应该是'this.state.show.section ===真的吗? secondarySection:mainSection'。谢谢安德鲁,注意。 – aitchnyu