Skip to content

Instantly share code, notes, and snippets.

@react-ram
Created October 22, 2019 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save react-ram/9b96b4294b67ea26f17e3c55e846bdff to your computer and use it in GitHub Desktop.
Save react-ram/9b96b4294b67ea26f17e3c55e846bdff to your computer and use it in GitHub Desktop.
basics - conditional rendering with inline logical && operator example
import React from "react";
const messages = ["react", "angular", "javascript"];
function App() {
return <MailBox unreadMessages={messages} />;
}
function MailBox(props) {
const unreadMessages = props.unreadMessages;
return (
<div>
{unreadMessages.length > 0 && (
<h2>you have {unreadMessages.length} unread messages</h2>
)}
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment