Created
August 22, 2021 09:51
-
-
Save gtchakama/38bd4740914ba9381be0c26e1cdc5cd7 to your computer and use it in GitHub Desktop.
Rendering Lists in React JS. -( map )
This file contains hidden or 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
import React from "react"; | |
import ReactDOM from "react-dom"; | |
const brands = ["Dell", "Huawei", "Samsung", "RedMi", "Apple"]; | |
const BrandList = () => ( | |
<div> | |
<ul>{brands.map(brand => <li key={brand}> {brand} </li>)}</ul> | |
</div> | |
); | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<BrandList />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rendering Lists in React JS.
This is a stateless component in React, which renders a div with a list. The individual list items are rendered using .map() to iterate over the names array initially created. This component is rendered using ReactDOM on the DOM element with Id of root.