-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToDoItemForm.js
49 lines (41 loc) · 919 Bytes
/
ToDoItemForm.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
import React from 'react';
import './ToDoList.css';
class ToDoItemForm extends React.Component{
constructor(props) {
super(props);
this.state = {
value: "",
}
}
InputChange = event => {
this.setState({ value: event.target.value });
}
addItem = () => {
const { value } = this.state;
if (value) {
this.props.addItem(value);
this.setState({value: ""});
} else{
alert("Введите задачу");
}
}
EnterPress = event => {
if (event.key === "Enter") this.addItem();
}
render() {
const { value } = this.state;
return(
<div className="ToDoItemForm">
<input
value={value}
placeholder="Введите задачу"
onChange={this.InputChange}
onKeyPress={this.EnterPress}
className="Input"
type="text"/>
<button onClick={this.addItem} className="addButton">ADD</button>
</div>
);
}
}
export default ToDoItemForm