Skip to content

Commit f522d6b

Browse files
committed
State x Object
1 parent c0d4243 commit f522d6b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/App.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
1+
import { useState } from 'react';
12
import './App.css';
23

34
function App() {
5+
const [note, setNote] = useState({
6+
content: '', author: ''
7+
});
8+
9+
function onNoteValueChange(event) {
10+
setNote((prevNote) => {
11+
return {
12+
...prevNote,
13+
[event.target.name]: event.target.value
14+
};
15+
});
16+
}
17+
418
return (
519
<section className="app-section">
620
<div className="app-container">
721
<h3>สักหน่อยมั้ยหละ</h3>
22+
<p>
23+
<textarea
24+
rows="3"
25+
placeholder="บันทึกความในใจ"
26+
name="content"
27+
value={note.content}
28+
onChange={onNoteValueChange}
29+
/>
30+
</p>
31+
<p>
32+
<input
33+
type="text"
34+
placeholder="ลงชื่อ"
35+
name="author"
36+
value={note.author}
37+
onChange={onNoteValueChange}
38+
/>
39+
</p>
840
</div>
941
</section>
1042
);

src/index.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ code {
1111
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
1212
monospace;
1313
}
14+
15+
input[type="text"],
16+
textarea {
17+
border: 1px solid gray;
18+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
19+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
20+
sans-serif;
21+
font-size: 16px;
22+
box-sizing: border-box;
23+
width: 100%;
24+
padding: 8px;
25+
}

0 commit comments

Comments
 (0)