๋ฆฌ์กํธ ๊ฐ๋ฐ ํ๋ฉด
์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋(๋ณ์, ํจ์ ...) ์ฌ์ฉ ์ { } ์ค๊ดํธ
ex) const name = "ใ
ใ
"
{ name }'s Diary
{ ${name}์ ์ค๋ ์์นจ ๋ฉ๋ด
}
4-1. ์ค๋ธ์ ํธ๋ฅผ ํํํ ๋๋ ์ค๊ดํธ ์ฌ์ฉ
4-2. ํจ์ ๋ด๋ถ์์ ์คํ์ผ์ํธ๋ฅผ ์ฌ์ฉํ ๋ ๊ฐ์ฒด ํํ๋ก ์ ์ (return ๋ด๋ถ)
ex) style={{width: "200px"}};
ํ๊ทธ๋ ๊ผญ ์์ผ๋ก ์์ด์ผ ํ๋ค. ๋ซ๋ ํ๊ทธ ์์ด ํ๋ก ์กด์ฌํ๋ ํ๊ทธ๋ค ๋ค์๋ ๋ฌด์กฐ๊ฑด '/'์ ๋ถ์ฌ์ผ ํจ (์ ํํด๋ก์ง)
์ปดํฌ๋ํธ๋ฅผ ์ ์(ํ์)ํ ๋๋ ํจ์๋ก, ํจ์๋ช ์ ๋๋ฌธ์๋ก ์์
React
import { Fragment } from "react";
// import React from "react";
import "./styles.css";
export default function App() {
const name = "๋๋ฆฌ";
const style = { color: "green" };
const lists = ["์ฐ์ ", "ํ ์คํธ", "๊ณ๋"];
const click = () => {
alert("๊ตฟ๋ชจ๋");
};
// ํ๋ฉด์ ๋ณด์ฌ์ง๋ ๋ถ๋ถ์ด ๋ง์
return (
<>
<div className="nav">
<h1>{name}'s Diary</h1>
</div>
<p style={style}>{`${name}์ ์ค๋ ์์นจ ๋ฉ๋ด`}</p>
<ul>
{/* <li>์ฐ์ </li>
<li>ํ ์คํธ</li>
<li>๊ณ๋</li> */}
{lists.map((item) => {
// map์ด ํ์คํ ๋ฆฌํด๊ฐ์ ๊ฐ์ง
return <li>{item}</li>;
// return console.log(item);
})}
</ul>
<img
style={{ width: "200px", border: "5px solid green" }}
src="https://images.unsplash.com/photo-1525351484163-7529414344d8?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80"
alt=""
title="ํด๋ฆญํด๋ณด์ธ์"
onClick={click}
/>
</>
);
}
index.js
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<StrictMode>
<App />
</StrictMode>
);
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>