Last active
October 1, 2021 02:28
-
-
Save Daniel-Walsh/4e38ceb2ab587b09fc9072619f614066 to your computer and use it in GitHub Desktop.
Loop through and render Object key/values with React JSX #react #jsx #objects
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
// Create an Array from the object's keys, then use .map() to loop through each | |
// key and return your new Array of JSX elements for rendering. Object values | |
// can be accessed using bracket notation. | |
const RenderObjectKeyValues = () => { | |
const recipeTags = { | |
asian: 1, | |
beef: 2, | |
breakfast: 2, | |
cakes: 2, | |
chicken: 2, | |
}; | |
return ( | |
<ul> | |
{Object.keys(recipeTags).map((key) => ( | |
<li> | |
{key} ({recipeTags[key]}) | |
</li> | |
))} | |
</ul> | |
); | |
}; | |
export default RenderObjectKeyValues; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment