Created
November 29, 2017 09:37
-
-
Save eddyerburgh/89aea2f23e95220e0e70aa0eff337437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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