Created
October 14, 2016 06:50
-
-
Save cauldyclark15/ab5a8274503b1c7dabd75d207316b3cc 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 React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import TodoTable from './all-todo'; | |
class CreateTodo extends React.Component { | |
constructor () { | |
super(); | |
this.state = { | |
count: 0, | |
data: [] | |
} | |
this.update = this.update.bind(this); | |
this.clearContent = this.clearContent.bind(this); | |
} | |
update () { | |
let tempHolder = this.state.data; | |
tempHolder.push({ | |
id: this.state.count, | |
content: this.refs.inp.value | |
}) | |
this.setState({ | |
count: this.state.count + 1, | |
data: tempHolder | |
}); | |
} | |
clearContent (e) { | |
e.target.value = ''; | |
} | |
render () { | |
return ( | |
<div> | |
<input | |
type="text" | |
ref="inp" | |
onFocus={this.clearContent} | |
/> | |
<button onClick={this.update} > | |
Create | |
</button> | |
<TodoTable tasks={this.state.data} /> | |
</div> | |
) | |
} | |
} | |
export default CreateTodo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment