Created
May 6, 2017 09:21
-
-
Save yhaskell/12780c7654c12bd80a28ee7c136cdedb to your computer and use it in GitHub Desktop.
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 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] | |
})) | |
} | |
} |
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
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