0

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.

1 Answer 1

2

The conditional operator would work:

{ schedules ? <ListItem items={schedules}/> : <h2>Hello World</h2> }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.