Last active
October 9, 2020 08:08
-
-
Save conormcafee/acbd8415018df43eebe2b01d97fe71d7 to your computer and use it in GitHub Desktop.
Example of how to use React.cloneElement
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
// BirthdayCardsList | |
/* | |
Before using React.cloneElement - I would have had this complicated component | |
which contained the logic for hide show, the menu item button itself, and then | |
the real purpose of this component, a list of links. | |
Now it is a lot easier as it has all of the logic required within its parent | |
component (MenuItem). All `BirthdayCardList` has to worry about now is | |
rendering a list of links. | |
*/ | |
const BirthdayCardsList = ({ isOpen }) => { | |
if (!isOpen) return null | |
return ( | |
<nav> | |
<a href="#">Funny Cards</a> | |
<a href="#">Age Cards</a> | |
</nav> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment