๐ Components ๋.
component๋ React ์ฑ์ ๊ตฌ์ฑํ๋ ๊ธฐ๋ณธ ๋จ์๋ก, ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ฝ๋์ ์กฐ๊ฐ์ ์๋ฏธํ๋ค.
๊ฐ๋จํ ๋งํด, ์ปดํฌ๋ํธ๋ UI์ ํ ๋ถ๋ถ์ ๋ด๋นํ๋ ์๋ฐ์คํฌ๋ฆฝํธ์ ํด๋์ค๋ ํจ์์ด๋ค.
๋ค์์ component ์ ์์์ด๋ค.
function Avatar(props) {
return (
<img className="Avatar"
src={props.user.avatarUrl}
alt={props.user.name}
/>
);
}
๐ Prop(property) ๋.
Prop์ component์ ์ ๋ฌํ๋ ๋ฐ์ดํฐ๋ก, ๋ถ๋ชจ component๋ก๋ถํฐ ์์ component๋ก ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ ๋ ์ฌ์ฉ๋๋ค.
๊ฐ๋จํ ์๋ก, 'Greeting' ์ด๋ผ๋ component๊ฐ ์๊ณ , ์ด component์ "name" ๊ณผ "age" ๋ผ๋ prop์ ํตํด ์ฌ์ฉ์์ ์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌํ ์ ์๋ค.
function Greeting(props) {
return <h1>Hello, {props.name}! I`m {props.age} years old.</h1>;
}
๊ทธ๋ฆฌ๊ณ ์ด 'Greeting' component๋ฅผ ์ฌ์ฉํ ๋๋ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ๋ค.
<Greeting name="Alice" age="21" />
<Greeting name="Brian" age="23" />
'react.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
State. (0) | 2024.03.17 |
---|---|
react.js ์ด์ฉ๋ฒ. (0) | 2024.03.10 |