다음은 완성된 전체 코드 입니다.
|
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
|
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React 예제 012</title>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="text/babel">
function Hanja(props) {
return (
<div>
{(props.hanja.index + "").padStart(3,0)}.
<b>{props.hanja.h}</b>
(<i style={{color:'red'}}>{props.hanja.k}</i> : {props.hanja.m})
: {props.hanja.t}
</div>
);
}
window.onload = () =>{
fetch("https://joongwoonc.github.io/data/chunja2.json")
.then((response) => {
console.log(response);
return response.json();
}).then((json) => {
ReactDOM.createRoot(document.querySelector('#app')).render(
<div>
<h1>천자문(千字文)</h1>
<hr/>
{
json.map((hanja) => {
return <Hanja key={hanja.index} hanja={hanja} />
})
}
</div>
);
});
}
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
|
cs |
다음은 실행 결과 입니다.


'Front End > React' 카테고리의 다른 글
| [React Exam 13] create-react-app를 이용한 Application 작성하기 (0) | 2024.10.15 |
|---|---|
| [React Exam 12] HTML로 시작해보는 React 보너스(박스오피스 보기) (1) | 2024.10.15 |
| [React Exam 10] HTML로 시작해보는 React 보너스(천자문 보기) (0) | 2024.10.15 |
| [React Exam 09] HTML로 시작해보는 React Component 속성 (1) | 2024.10.15 |
| [React Exam 08] HTML로 시작해보는 React Component (2) | 2024.10.15 |