Skip to content

Instantly share code, notes, and snippets.

@yhaskell
Created May 6, 2017 09:21
Show Gist options
  • Save yhaskell/12780c7654c12bd80a28ee7c136cdedb to your computer and use it in GitHub Desktop.
Save yhaskell/12780c7654c12bd80a28ee7c136cdedb to your computer and use it in GitHub Desktop.
import render from './my-awesome-component.render'
class MyAwesomeComponent extends Component {
constructor() {
super()
this.state = {
data: ['First item', 'Second Item']
}
this.render = render.bind(this)
}
onAddItem(item) {
this.setState(state => ({
data: [...state.data, item]
}))
}
}
export default const render = () => (
<div>
<ul>
{this.state.data.map((item, index) => <li key={index}>{item}</li>)}
</ul>
<div>
<input ref={input => this.input = input} placeholder="Add new word..." />
<button onClick={() => this.onAddItem(this.input.value)}>Add</button>
</div>
</div>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment