Created
May 17, 2021 19:39
-
-
Save pflevy/6a03707a7628a0ce7edbd123d999d571 to your computer and use it in GitHub Desktop.
Using React.Fragment with conditional rendering and storing JSX on a variable.
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
const MyComponent = (props) => { | |
const renderFullHeader = () => { | |
return ( | |
<> | |
<h2>{entry.header}</h2> | |
<h3>{entry.subheader}</h3> | |
</> | |
); | |
}; | |
return ( | |
<> | |
{props.fullHeader ? ( | |
renderFullHeader() | |
) : ( | |
<span> | |
{entry.header} {entry.subheader} | |
</span> | |
)} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment