Elements
- ๋ฆฌ์กํธ ์ฑ์ ๊ตฌ์ฑํ๋ ๊ฐ์ฅ ์์ ๋ธ๋ก๋ค
- ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ฒด ํํ๋ก ์กด์ฌ.
- ์ปดํฌ๋ํธ ๋ ๋๋ง์ ์ํด ๋ชจ๋ ์ปดํฌ๋ํธ๊ฐ createElement๋ฅผ ํตํด ์๋ฆฌ๋จผํธ๋ก ๋ณํ๋๋ค.
Elements์ ํน์ง
- immutable : ๋ณ๊ฒฝํ ์ ์๋ (๋ถ๋ณ์)
- ์๋ฆฌ๋จผํธ ์์ฑ ํ์๋ children์ด๋ attributes๋ฅผ ๋ฐ๊ฟ ์ ์๋ค.
Root DOM Node
- ๋ชจ๋ ๋ฆฌ์กํธ ์ฑ์ ๋จ ํ๋์ Root DOM Node๋ฅผ ๊ฐ์ง๊ฒ ๋๋ค.
<div id="root"></div>
- ์๋ฆฌ๋จผํธ ์์ฑ ํ root div์ ๋ ๋๋ง
- ๋ ๋๋ง : ReactDOM.render() ์ฌ์ฉ
const element = <h1>์๋
๋ฆฌ์กํธ!</h1>;
ReactDOM.render(**element**, **document.getElementById('root')**);
=> ReactDOM.rentder(A, B); : A๋ฅผ B์์น์ ๋ ๋๋ง
์๊ณ ๋ง๋ค๊ธฐ
Clock.jsx
import React from "react";
function Clock(props) {
return (
<div>
<h1>์๋
, ๋ฆฌ์กํธ!</h1>
<h2>ํ์ฌ์๊ฐ์ {new Date().toLocaleTimeString()} ์ด์ผ.</h2>
</div>
);
}
export default Clock;
index.js
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import reportWebVitals from "./reportWebVitals";
import Clock from "./chapter_04/Clock";
const root = ReactDOM.createRoot(document.getElementById("root"));
setInterval(() => {
root.render(
<React.StrictMode>
<Clock />
</React.StrictMode>
);
}, 1000);
reportWebVitals();
'Web > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] 6. Components and Props (0) | 2023.11.05 |
---|---|
[React] Error: react_dom_client__WEBPACK_IMPORTED_MODULE_1__.render is not a function (0) | 2023.11.05 |
[React] Error: Already included file name (0) | 2023.11.05 |
[React] 4. JSX (0) | 2023.11.05 |
[React] 3. ๋ฆฌ์กํธ ์์ํ๊ธฐ (0) | 2023.11.04 |