-
Notifications
You must be signed in to change notification settings - Fork 4
/
Lab22.txt
61 lines (56 loc) · 1.58 KB
/
Lab22.txt
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
import logo from './logo.svg';
import './App.css';
import React, { useState } from "react";
function App() {
const [customer, _setCustomer] = useState({ name: "", code: "" });
const [customers, _setCustomers] = useState([]);
const setCustomer = e => {
_setCustomer(prevState => ({
...prevState,
[e.target.name]: e.target.value
}));
};
const setCustomers = e => {
_setCustomers(prevState => (
[...prevState, customer]
));
_setCustomer(prevState => ({
...prevState,
name: "", code: ""
}));
fetch('https://localhost:44393/Home/Submit', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(customer)
})
};
return (
<div className="App">
{customer.name} {customer.code}
<input value={customer.name} onChange={setCustomer} type="text" name="name"/>
<input value={customer.code} onChange={setCustomer} type="text" name="code"/>
<input value="Add" type="button" onClick={setCustomers}/><br>
</br>
<table>
<thead>
<tr>
<td>Name</td>
<td>code</td>
</tr>
</thead>
<tbody>
{customers.map((x,index) => (
<tr key={index}>
<td>{x.name}</td>
<td>{x.code}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
export default App;