[React]_attribute 대신 children

hanseungjune·2022년 6월 29일
0

React

목록 보기
8/10

✅ children

function Button({ text }) {
  return <button>{text}</button>;
}
<div>
  <Button text="던지기"/>
  <Button text="처음부터"/>
  <Dice color="red" num={4} />
</div>

▶ 위의 코드를! children이라는 props를 활용하면!

function Button({ children }) {
  return <button>{children}</button>;
}
<div>
  <Button>던지기</Button>
  <Button>처음부터</Button>
  <Dice color="red" num={4} />
</div>

▶ 이렇게 된다!

결론은 children을 쓰는게 편하다.

profile
필요하다면 공부하는 개발자, 한승준

0개의 댓글