-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
74 lines (52 loc) · 1.5 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { Component } from 'react';
import './App.css';
import TodoList from './components/TodoList';
class App extends Component {
constructor(props){
super(props);
this.state = {
items: [{text:'todo1', id: '33445'}],
noteText : '',
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e){
this.setState({noteText: e.target.value})
}
handleSubmit(e){
e.preventDefault();
if(!this.state.noteText.length){
return;
}
const newItem ={
text: this.state.noteText,
id: Date.now()
};
this.setState(prevState => ({
items: prevState.items.concat(newItem),
noteText: ''
}));
}
render() {
return (
<div className="App">
<div className="container" >
<div className="header">React Todo Application</div>
<TodoList items={this.state.items}/>
<form >
<input type="text"
placeholder="What needs to be done? ..."
ref={((input) => {this.textInput = input})}
className="textInput"
value={this.state.noteText}
onChange={this.handleChange}
/>
<div className="btn" onClick={this.handleSubmit}> + </div>
</form>
</div>
</div>
);
}
}
export default App;