웹프로그래밍/react

react 공부하기 3

발전하는개발자 2019. 5. 21. 16:26

props와 state를 이용한 react 기초 소스

react component에서 다루는 데이터는 props와 state로 나뉩니다. 

props : 부모 컴포넌트가 자식 컴포넌트에게 주는 값입니다. 자식 컴포넌트에서는 props를 받아오기만 하고 받아온 props를 직접 수정할 수는 없습니다.

state : 컴포넌트 내부에서 선언하며 내부에서 값을 변경 할 수 있습니다.

 

See the Pen simple ex1 by hyunseo91 (@hyunseo91) on CodePen.

 

 

위의 소스를 react props를 이용해 다시 작성 했을 때

 

See the Pen zQEQge by hyunseo91 (@hyunseo91) on CodePen.

 

 

 

위의 소스를 react state를 이용해 다시 작성 했을 때

 

See the Pen react state ex1 by hyunseo91 (@hyunseo91) on CodePen.

반응형