Conditional Rendering – React

PHOTO EMBED

Mon Jan 24 2022 21:39:34 GMT+0000 (UTC)

Saved by @joel113 #javascript #react.js

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')
);
content_copyCOPY

https://reactjs.org/docs/conditional-rendering.html