Conditional Rendering: Inline If with Logical && Operator

function Mailbox(props) {
  const unreadMessages = props.unreadMessages;
  return (
    <div>
      <h1>Hello!</h1>
      {unreadMessages.length > 0 &&
        <h2>
          You have {unreadMessages.length} unread messages.
        </h2>
      }
    </div>
  );
}

const messages = ['React', 'Re: React', 'Re:Re: React'];
ReactDOM.render(
  <Mailbox unreadMessages={messages} />,
  document.getElementById('root')
);

You may embed any expressions in JSX by wrapping them in curly braces.

Related concepts

Inline If with Logical && Operator

Conditional Rendering: Inline If with Logical && Operator — Structure map

Clickable & Draggable!

Conditional Rendering: Inline If with Logical && Operator — Related pages: