Skip to content

Instantly share code, notes, and snippets.

@gtchakama
Created August 22, 2021 09:51
Show Gist options
  • Save gtchakama/38bd4740914ba9381be0c26e1cdc5cd7 to your computer and use it in GitHub Desktop.
Save gtchakama/38bd4740914ba9381be0c26e1cdc5cd7 to your computer and use it in GitHub Desktop.
Rendering Lists in React JS. -( map )
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);
@gtchakama
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment