我想知道在ReactJS JSX中是否可以嵌套if-else if?
我try 过各种不同的方法,但我无法让它发挥作用.
我在找
if (x) {
loading screen
} else {
if (y) {
possible title if we need it
}
main
}
我已经试过了,但是我不能把它渲染出来.我试过各种方法.一旦我添加嵌套的if,它总是会中断.
{
this.state.loadingPage ? (
<div>loading page</div>
) : (
<div>
this.otherCondition && <div>title</div>
<div>body</div>
</div>
);
}
Update
我最终 Select 了解决方案,将其移动到renderContent并调用该函数.不过,这两个答案都有效.我想我可以使用内联解决方案,如果它用于简单的渲染,而对于更复杂的情况,则使用renderContent.
非常感谢.