Created
November 20, 2018 06:23
-
-
Save castaneai/155468c6310fc036c3d3f4fbdcfdce1f to your computer and use it in GitHub Desktop.
react list start
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
import React, { Component } from 'react'; | |
import './App.css'; | |
import ItemList from "./ItemList"; | |
import Item from "./Item"; | |
interface Props { | |
} | |
interface State { | |
items: Item[] | |
} | |
class App extends Component<Props, State> { | |
constructor(props: Props) { | |
super(props) | |
this.state = { | |
items: [ | |
{ id: "12345", name: "testname" }, | |
{ id: "12345", name: "testname2" } | |
] | |
} | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<ItemList items={this.state.items} /> | |
</div> | |
); | |
} | |
} | |
export default App; |
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
interface Item { | |
id: string | |
name: string | |
} | |
export default Item |
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
import React, { Component } from 'react'; | |
import Item from './Item'; | |
interface Props { | |
items: Item[] | |
} | |
class ItemList extends Component<Props> { | |
createItem(item: Item) { | |
return <li key={item.id}>{item.name}</li> | |
} | |
render() { | |
const listItems = this.props.items.map(this.createItem) | |
return ( | |
<ul className="itemList">{listItems}</ul> | |
) | |
} | |
} | |
export default ItemList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment