<h1>Hi</h1>
<h3>hi</h3>
를 찍어내보자
const rootElement = document.getElementById("root");
const paint = () => (
<>
<h1>Hi</h1>
<h3>hi</h3>
</>
);
const element = (
<>
{paint()}
{paint()}
{paint()}
</>
);
ReactDOM.render(element, rootElement);
성공적.
const rootElement = document.getElementById("root");
const paint = (title, description) => (
<>
<h1>{title}</h1>
<h3>{description}</h3>
</>
);
const element = (
<>
{paint("Good", "good")}
{paint("Bad", "bad")}
{paint("Soso", "soso")}
</>
);
ReactDOM.render(element, rootElement);
const rootElement = document.getElementById("root");
// paint -> Paint
// 함수 이름 대문자로 바꿔야함
const Paint = ({title, description}) => (
<>
<h1>{title}</h1>
<h3>{description}</h3>
</>
);
const element = (
<>
<Paint title="Haha" description="haha" />
<Paint title="Hoho" description="hoho" />
<Paint title="Huhu" description="huhu" />
</>
);
ReactDOM.render(element, rootElement);
<p>
나 <span>
같은 태그로 착각하지 않기 하기 위함! (custom-element 라고도 한다)const rootElement = document.getElementById("root");
const Paint = ({ title, description, children }) => (
<>
<h1>{title}</h1>
<h3>{description}</h3>
{children}
</>
);
const element = (
<>
<Paint title="Haha" description="haha">
hahaha!!
</Paint>
<Paint title="Hoho" description="hoho">
hohoho!!
</Paint>
<Paint title="Huhu" description="huhu">
huhuhu!!
</Paint>
</>
);
ReactDOM.render(element, rootElement);
React.Fragment
(<>)에 있는 자식 요소를 <Paint>
가 자동대로 children 인자로 받음! (신기)const Paint = ({ title, description, children }) ...
이 부분의 {title, description, children}
은 props가 된다!