-
[10]State와 Props의 차이dev/Web 2021. 4. 12. 19:03
State와 Props 둘 다 컴포넌트에서 사용하거나, 렌더링 할 데이터를 담고 있으므로 비슷해 보일 수 있지만 매우 다르다.
props는 부모 컴포넌트가 설정하고, state는 컴포넌트 자체적으로 지닌 값으로 컴포넌트 내부에서 값을 업데이트 할 수 있다.
props를 사용한다고 무조건 값이 고정적이지는 않다. 부모 컴포넌트의 state를 자식 컴포넌트의 props로 전달하고 자식 컴포넌트에서 특정 이벤트를 발생할 때 부모 컴포넌트의 메서드를 호출하면 props를 유동적으로 사용할 수 있다.
'dev > Web' 카테고리의 다른 글
[12]setState()의 인수로서 콜백 함수의 목적 (0) 2021.04.12 [11]State를 직접적으로 업데이트 하면 안되는 이유 (0) 2021.04.12 [9]React에서 Prop은 무엇인가? (0) 2021.04.12 [8]React에서 state는 무엇인가? (0) 2021.04.12 [7]Pure Component가 뭔가? (0) 2021.04.12