공부를 하다가 JSX에서 중괄호 { }를 사용할 때와 사용하지 않을 때의 차이가 궁금해서
알아보려고 한다!!!
function App() {
const name ="React";
const viewCount = 1500;
return (
<div>
<h1>이름: {name}</h1>
<p>조회수: {viewCount}</p>
</div>
);
}
const name ="React";
<h1>{name}</h1> // React
const count = 5;
<p>{count}</p> // 5
const getMessage = () => "Hello, World!";
<h2>{getMessage())</h2> // Hello, world!
const isLoggedIn = true;
<p>{isLoggedIn ? "Welcome!" : "Please log in."}</p> // Welcome!
<Layout
header={<Header title="Welcome!" />}
footer={<Footer />}
/>
function App() {
return (
<div>
<h1 title="React Tutorial">안녕하세요!</h1>
</div>
);
}
주요 사례:
<h1 title="Welcome">Hello</h1>
<div className="container"></div>
<img src="https://example.com/image.png" alt="Example Image" />
1. 중괄호{}:
2. 큰따옴표 " ":
<h1 title={"hello"}>안녕하세요!</h1>
const name="React";
<h1 title="name"></h1> // "name"그대로 렌더링이 된다.