Last active
August 25, 2020 19:33
-
-
Save jamiejohnsonkc/16e0854981f447e6f630803ab24e16fb to your computer and use it in GitHub Desktop.
Simple Dynamic List via mapping
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
/** @jsx jsx */ | |
import { jsx } from 'theme-ui' | |
import React from 'react' | |
const list = ['a', 'b', 'c'] | |
const SimpleUlList = () => ( | |
<ul> | |
{list.map((item) => ( | |
<li key={item}>{item}</li> | |
))} | |
</ul> | |
) | |
export default SimpleUlList | |
//If we would use the List as child component in another component, we could pass the list as props to it: | |
const mylist = ['a', 'b', 'c']; | |
const App = () => ( | |
<SimpleList list={mylist} /> | |
) | |
const SimpleList = ({ list }) => ( | |
<ul> | |
{list.map(item => ( | |
<li key={item}>{item}</li> | |
))} | |
</ul> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment