Skip to content

Instantly share code, notes, and snippets.

@johann-sonntagbauer
Created March 3, 2017 11:56
Show Gist options
  • Save johann-sonntagbauer/72f854968f902102fe1510d0177f1f72 to your computer and use it in GitHub Desktop.
Save johann-sonntagbauer/72f854968f902102fe1510d0177f1f72 to your computer and use it in GitHub Desktop.
app
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