-
Notifications
You must be signed in to change notification settings - Fork 4
/
Lab12(SimpleScreen).txt
56 lines (50 loc) · 1.35 KB
/
Lab12(SimpleScreen).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
-- This code you ave to copy in the
-- create react template..
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: ""
}));
};
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;