-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathApp4.js
97 lines (86 loc) · 2.5 KB
/
App4.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React, { Component } from 'react';
/*
add a board (post)
*/
class App4 extends Component {
state = {
maxNo: 3,
boards: [
{
brdno: 1,
brdwriter: 'Lee SunSin',
brdtitle: 'If you intend to live then you die',
brddate: new Date()
},
{
brdno: 2,
brdwriter: 'So SiNo',
brdtitle: 'Founder for two countries',
brddate: new Date()
}
]
}
handleSaveData = (data) => {
this.setState({
boards: this.state.boards.concat({ brdno: this.state.maxNo++, brddate: new Date(), ...data })
});
}
render() {
const { boards } = this.state;
return (
<div>
<BoardForm onSaveData={this.handleSaveData}/>
<table border="1">
<tbody>
<tr align="center">
<td width="50">No.</td>
<td width="300">Title</td>
<td width="100">Name</td>
<td width="100">Date</td>
</tr>
{
boards.map(function(row){
return (<BoardItem key={row.brdno} row={row} />);
})
}
</tbody>
</table>
</div>
);
}
}
class BoardItem extends React.Component {
render() {
return(
<tr>
<td>{this.props.row.brdno}</td>
<td>{this.props.row.brdtitle}</td>
<td>{this.props.row.brdwriter}</td>
<td>{this.props.row.brddate.toLocaleDateString('ko-KR')}</td>
</tr>
);
}
}
class BoardForm extends Component {
state = {}
handleChange = (e) => {
this.setState({
[e.target.name]: e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault();
this.props.onSaveData(this.state);
this.setState({});
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<input placeholder="title" name="brdtitle" onChange={this.handleChange}/>
<input placeholder="name" name="brdwriter" onChange={this.handleChange}/>
<button type="submit">Save</button>
</form>
);
}
}
export default App4;