https://ko.react.dev/learn/your-first-component
โฉ ์น์์ ์ํธ์์ฉ์ด ์ค์ํ๋ ์์ ์ ํจ๊ณผ์
React ์ปดํฌ๋ํธ๋ ๋งํฌ์
์ผ๋ก ๋ฟ๋ฆด ์ ์๋ JavaScript ํจ์
export default function Profile() {
return (
<img
src="https://i.imgur.com/MK3eW3Am.jpg"
alt="Katherine Johnson"
/>
)
}
๋ด๋ณด๋ผ ํจ์ ์ ์
React ์ปดํฌ๋ํธ๋ ์ผ๋ฐ JavaScript ํจ์์ด์ง๋ง, ์ด๋ฆ์ ๋๋ฌธ์๋ก ์์ํด์ผ ํจ
๋งํฌ์ ์ถ๊ฐ
return <img src="https://i.imgur.com/MK3eW3As.jpg" alt="Katherine Johnson" />;
return (
<div>
<img src="https://i.imgur.com/MK3eW3As.jpg" alt="Katherine Johnson" />
</div>
);
<img />
ํ๊ทธ๋ฅผ ๋ฐํ <img />
๋ HTML์ฒ๋ผ ์์ฑ๋์์ง๋ง ์ค์ ๋ก๋ JavaScript JSX
๋ผ๊ณ ํ๋ฉฐ, JavaScript ์์ ๋งํฌ์
์ ์ฝ์
function Profile() {
return (
<img
src="https://i.imgur.com/MK3eW3As.jpg"
alt="Katherine Johnson"
/>
);
}
export default function Gallery() {
return (
<section>
<h1>Amazing scientists</h1>
<Profile />
<Profile />
<Profile />
</section>
);
}
๋ธ๋ผ์ฐ์ ์ ํ์๋๋ ๋ด์ฉ
๋์๋ฌธ์ ์ฐจ์ด์ ์ฃผ๋ชฉ
<section>
์ ์๋ฌธ์์ด๋ฏ๋ก React๋ HTMLํ๊ทธ๋ฅผ ๊ฐ๋ฆฌํจ๋ค๊ณ ์ปดํ์ผ<Profile />
์ ๋๋ฌธ์ p
๋ก ์์ํ๋ฏ๋ก React
๋ Profile
์ด๋ผ๋ ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๊ณ ์ ํ๋ค๊ณ ์ปดํ์ผ<img />
๊ฐ ํฌํจ๋ธ๋ผ์ฐ์ ์ ํ์๋๋ ๋ด์ฉ
<section>
<h1>Amazing scientists</h1>
<img src="https://i.imgur.com/MK3eW3As.jpg" alt="Katherine Johnson" />
<img src="https://i.imgur.com/MK3eW3As.jpg" alt="Katherine Johnson" />
<img src="https://i.imgur.com/MK3eW3As.jpg" alt="Katherine Johnson" />
</section>
Profile
์ปดํฌ๋ํธ๋ Gallery
์์์ ์ฌ๋ฌ๋ฒ ๋ ๋๋งGallery
๋ ๊ฐ Profil
์ โ์์โ์ผ๋ก ๋ ๋๋งํ๋ "๋ถ๋ชจ" ์ปดํฌ๋ํธโ ์ปดํฌ๋ํธ๋ ๋ค๋ฅธ ์ปดํฌ๋ํธ๋ฅผ ๋ ๋๋งํ ์ ์์ง๋ง, ๊ทธ ์ ์๋ฅผ ์ค์ฒฉํด์๋ ์ ๋ฉ๋๋ค. โ
์ต์์ ๋ ๋ฒจ์์ ์ปดํฌ๋ํธ๋ฅผ ์ ์
์์ ์ปดํฌ๋ํธ์ ๋ถ๋ชจ ์ปดํฌ๋ํธ์ ์ผ๋ถ ๋ฐ์ดํฐ๊ฐ ํ์ํ ๊ฒฝ์ฐ props๋ก ์ ๋ฌ
export default function Gallery() {
// ๐ด ์ ๋ ์ปดํฌ๋ํธ ์์ ๋ค๋ฅธ ์ปดํฌ๋ํธ๋ฅผ ์ ์ํ๋ฉด ์ ๋จ
function Profile() {
// ...
}
// ...
}
export default function Gallery() {
// ...
}
// โ
์ต์์ ๋ ๋ฒจ์์ ์ปดํฌ๋ํธ๋ฅผ ์ ์ธ
function Profile() {
// ...
}
React ์ ํ๋ฆฌ์ผ์ด์
์ root
์ปดํฌ๋ํธ์์ ์์
๋ณดํต ์ ํ๋ก์ ํธ๋ฅผ ์์ํ ๋ ์๋์ผ๋ก ์์ฑ
Next.js๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, root ์ปดํฌ๋ํธ๋ pages/index.js์ ์ ์
React ์ฑ์ ๋ชจ๋ ๋ถ๋ถ์์ ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉ
๋ฒํผ๊ณผ ๊ฐ์ด ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๋ถ๋ถ๋ฟ๋ง ์๋๋ผ ์ฌ์ด๋๋ฐ, ๋ชฉ๋ก ๋ฑ๋ฑ...
๊ถ๊ทน์ ์ผ๋ก ์ ์ฒด ํ์ด์ง์ ๊ฐ์ ํฐ ๋ถ๋ถ์๋ ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉ
์ปดํฌ๋ํธ๋ ํ ๋ฒ๋ง ์ฌ์ฉ๋๋๋ผ๋ UI ์ฝ๋์ ๋งํฌ์ ์ ์ ๋ฆฌํ๋ ํธ๋ฆฌํ ๋ฐฉ๋ฒ
React๋ฅผ ์ฌ์ฉํ๋ฉด ์ฑ์ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ UI ์์์ธ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค ์ ์๋ค.
React ์ฑ์์ ๋ชจ๋ UI๋ ์ปดํฌ๋ํธ์ ๋๋ค.
React ์ปดํฌ๋ํธ๋ ๋ค์ ๋ช ๊ฐ์ง๋ฅผ ์ ์ธํ๊ณ ๋ ์ผ๋ฐ์ ์ธ JavaScript ํจ์์ด๋ค.
1. ์ปดํฌ๋ํธ์ ์ด๋ฆ์ ํญ์ ๋๋ฌธ์๋ก ์์
2. JSX ๋งํฌ์
์ ๋ฐํ