props properties를 줄인 표현으로 컴포넌트 속성을 설정할 때 사용하는 요소이다. props 값은 해당 컴포넌트를 불러와 사용하는 부모 컴포넌트에서만 설정할 수 있다. 


[props 값 설정 및 검증]



props 검증 : propTypes은 컴포넌트의 필수 props를 지정하거나 props 타입을 지정할  때 사용한다.

1
2
import PropTypes from 'prop-types';
 
cs


1
2
3
4
static propTypes = {
    navigator : PropTypes.object,
    componentId : PropTypes.string
  }

cs


필수 propTypes 설정

1
2
3
4
5
6
static propTypes = {
 
 name : PropTypes.string,
 age : PropTypes.number.isRequired
 
}

cs


발췌 : 리액트를 다루는 기술 

블로그 이미지

클라인STR

,