Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ์๊ณ ๋ฆฌ์ฆ
- ๋ ธ๋ง๋์ฝ๋
- heapq
- error
- ํฌ๋กค๋ง
- ๊ฐ๋ฐ
- ๋ชจ๊ฐ์ฝ
- KDT
- ๊ทธ๋ฆฌ๋
- Til
- JS
- ์ฝ๋ฉ์ ํ
- ๋ฐฑ์ค
- ํ๋ก ํธ์๋
- HTML
- ๊ตญ๋น์ง์
- javascript
- ํ๋ก๊ทธ๋๋จธ์ค
- ํ์ด์ฌ
- mongodb
- ์ฝ๋ฉํ ์คํธ
- ๋๋ฆผ์ฝ๋ฉ
- fe
- node.js
- Python
- react
- ํ ์ดํ๋ก์ ํธ
- ํ๋ก์ ํธ
- ์ฝ๋ฉ
- CSS
Archives
- Today
- Total
๐ฑ → ๐ณ
[React] React.Fragment ๋ณธ๋ฌธ
728x90
React.Fragment
์ค์ ๋ฆฌ์กํธ์์ ์ปดํฌ๋ํธ๋ฅผ ์กฐํฉํ ๋, ์ต์์์ div๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๋ฐํํด์ผํ๋ ๊ฒฝ์ฐ๊ฐ ์๊น
css๊ฐ ๊นจ์ง๋ค๊ฑฐ๋, ํ ์ด๋ธ ์์ ์ฌ์ด์ div์์๊ฐ ๋ค์ด๊ฐ๋ฉด error๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ
React.Fragment๋ก return ๊ฐ์์ ์ต์์ tag ์ญํ ์ ํ๋ div ์์ ๊ธฐ
import React from "react";
export default function ReactFragment() {
return (
<React.Fragment>
<h1>์๋
ํ์ธ์!</h1>
<span>๋ฐ๊ฐ์ต๋๋ค!</span>
</React.Fragment>
);
}
(react ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ๋ฅ์ด๋ฏ๋ก react ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ ํ์)
<> </>
React.Fragment๋ <>๋ก ๋์ฒด ๊ฐ๋ฅ !
import React from "react";
export default function ReactFragment() {
return (
<>
<h1>์๋
ํ์ธ์!</h1>
<span>๋ฐ๊ฐ์ต๋๋ค!</span>
</>
);
}
โ๏ธ ํ์ ์์)
ํ ์ด๋ธ ์์์์๋ div tag๊ฐ ๋ค์ด๊ฐ์ง ๋ชปํจ
์ด๋ด๋ ๋ฌธ์ ๊ฐ ์๊ธฐ๋๋ฐ ์ด๊ฒ์ react.fragment๋ก ํด๊ฒฐ ๊ฐ๋ฅ
import TableColumn from "./components/TableColumn";
function App() {
return (
<div className="App">
<table border="1">
<tbody>
<tr border="1">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<TableColumn />
</tr>
</tbody>
</table>
</div>
);
}
export default App;
// error ๋ฐ์ํ๋ ์ํฉ
import React from "react";
export default function ReactFragment() {
return (
<div>
<td>a</td>
<td>b</td>
<td>c</td>
</div>
);
}
// error ํด๊ฒฐ !
import React from "react";
export default function ReactFragment() {
return (
<>
<td>a</td>
<td>b</td>
<td>c</td>
</>
);
}
728x90
'Client > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] useState vs useRef vs Variable (0) | 2022.09.30 |
---|---|
[React] JSX (Javascript XML) (1) | 2022.09.26 |