flash
flash

Reputation: 1519

How to add else block in Inline If with Logical && Operator in react?

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

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 370759

The conditional operator would work:

{ schedules ? <ListItem items={schedules}/> : <h2>Hello World</h2> }

Upvotes: 2

Related Questions