組件之一下面是我的代碼收到錯誤:「一個有效的做出反應元素(或空)必須返回」錯誤與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