-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (49 loc) · 1.27 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
import React, { Component } from "react";
import { render } from "react-dom";
import PropTypes from "prop-types";
import "./app.css";
import Header from "./components/Header";
import Form from "./components/Form";
import ListItems from "./components/ListItems";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
todoItem: "",
items: ["吃苹果🍎", "吃香蕉🍌🍌🍌", "喝奶茶☕️️️️️️️️☕️"]
};
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
onChange(event) {
this.setState({
todoItem: event.target.value
});
}
onSubmit(event) {
event.preventDefault();
this.setState({
todoItem: "",
items: [...this.state.items, this.state.todoItem]
})
}
render() {
return (
<div className="container">
<Header title="TodoList" />
<Form
onSubmit={this.onSubmit}
onChange={this.onChange}
todoItem={this.state.todoItem}
/>
<ListItems items={this.state.items} />
</div>
);
}
}
App.propTypes = {
items: PropTypes.array,
todoItem: PropTypes.string,
onChange: PropTypes.func
};
render(<App />, document.getElementById("app"));