Skip to content

Commit 2b9a111

Browse files
committed
forwardRef
1 parent 042ddad commit 2b9a111

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/App.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useRef } from 'react';
22
import './App.css';
3+
import SelectTextarea from './SelectTextarea';
4+
import SendFile from './SendFile';
35

46
function App() {
57
const textareaRef = useRef(null);
@@ -17,18 +19,8 @@ function App() {
1719
return (
1820
<section className="app-section">
1921
<div className="app-container">
20-
<p>
21-
<textarea ref={textareaRef}></textarea>
22-
</p>
23-
<p>
24-
<button onClick={onSelectTextClick}>เลือกข้อความทั้งหมด</button>
25-
</p>
26-
<p>
27-
<input type="file" ref={fileRef} />
28-
</p>
29-
<p>
30-
<button onClick={onSendClick}>ส่งไฟล์</button>
31-
</p>
22+
<SelectTextarea onSelectTextClick={onSelectTextClick} ref={textareaRef} />
23+
<SendFile onSendClick={onSendClick} ref={fileRef} />
3224
</div>
3325
</section>
3426
);

src/SelectTextarea.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
const SelectTextarea = React.forwardRef((props, ref) => {
4+
return (
5+
<div>
6+
<p>
7+
<textarea ref={ref}></textarea>
8+
</p>
9+
<p>
10+
<button onClick={props.onSelectTextClick}>เลือกข้อความทั้งหมด</button>
11+
</p>
12+
</div>
13+
);
14+
});
15+
16+
export default SelectTextarea;

src/SendFile.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
const SendFile = React.forwardRef((props, ref) => {
4+
return (
5+
<div>
6+
<p>
7+
<input type="file" ref={ref} />
8+
</p>
9+
<p>
10+
<button onClick={props.onSendClick}>ส่งไฟล์</button>
11+
</p>
12+
</div>
13+
);
14+
});
15+
16+
export default SendFile;

0 commit comments

Comments
 (0)