Skip to content

Instantly share code, notes, and snippets.

@eddyerburgh
Created November 29, 2017 09:37
Show Gist options
  • Save eddyerburgh/89aea2f23e95220e0e70aa0eff337437 to your computer and use it in GitHub Desktop.
Save eddyerburgh/89aea2f23e95220e0e70aa0eff337437 to your computer and use it in GitHub Desktop.
// inline conditional rendering
const Page = () => (
<Modal>
{ showModalHeader && (
<ModalHeader />
)}
{ showModalMessage && (
<showModalMessage />
)}
{showOkButton ? <OkButton /> : <CloseButton />}
</Modal>
)
// conditional rendering
// conditional rendering in seperate functions leads to a larger bundle size
function ModalHeader(showModalHeader) {
if (showModalHeader) {
return <ModalHeader />;
}
}
function ModalMessage(showModalMessage) {
if (showModalHeader) {
return <ModalHeader />;
}
}
function ModalButton(showOkButton) {
if (showOkButton) {
return <OkButton />
}
return <CloseButton />
}
const Page = ({ showModalHeader, showModalMessage }) => (
<Modal>
{ModalHeader(showModalHeader)}
{ModalMessage(showModalMessage)}
{ModalButton(showOkButton)}
</Modal>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment