Reputation: 1519
I have a react code as shown below which uses inline if with logic && operator in react:
{ schedules && <ListItem items={schedules}/> } // Line A
{ schedules==null && <h2>Hello World</h2>} // Line B
Line A prints list of schedules and Line B prints Hello World
on the webpage if there are no schedules.
I am wondering how I can merge Line A and Line B.
Upvotes: 0
Views: 638
Reputation: 370759
The conditional operator would work:
{ schedules ? <ListItem items={schedules}/> : <h2>Hello World</h2> }
Upvotes: 2