-
-
Save johann-sonntagbauer/72f854968f902102fe1510d0177f1f72 to your computer and use it in GitHub Desktop.
app
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'; | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
entries: ['Stefanie', 'Sepp', 'Alex'] | |
} | |
} | |
render() { | |
return <div> | |
<Input/><Button onClick={(e) => {console.log('click')}}/> | |
<List entries={this.state.entries}/> | |
</div> | |
} | |
} | |
function Input() { | |
return <input type="text" onChange={(e) => console.log(e.target.value)}/> | |
} | |
function Button({onClick}) { | |
return <button onClick={onClick} | |
>+</button> | |
} | |
function List({entries}) { | |
return <div> | |
{ | |
entries.map( | |
(entry, index) => | |
<Person key={index} name={entry}/>) | |
} | |
</div> | |
} | |
function Person ({name}) { | |
return <div>Name: {name}</div> | |
} | |
Person.propTypes = { | |
name: React.PropTypes.string | |
} | |
ReactDOM.render( | |
<App /> | |
, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment