리액트 컴포넌트에서 Props의 타입들을 지정하여 일치하지 않을 시에 오류를 뱉게 할 수 있다.
PropTypes.any
: The prop can be of any data type
PropTypes.bool
: The prop should be a Boolean
PropTypes.number
: The prop should be a number
PropTypes.string
: The prop should be a string
PropTypes.func
: The prop should be a function
PropTypes.array
: The prop should be an array
PropTypes.object
: The prop should be an object
PropTypes.symbol
: The prop should be a symbol
Component.propTypes = { anyProp: PropTypes.any, booleanProp: PropTypes.bool, numberProp: PropTypes.number, stringProp: PropTypes.string, functionProp: PropTypes.func }
이게 좀 헷갈렸다.
node
와 element
가 있다.
node : 이것은 React가 render 할 수 있는 모든 것을 의미한다고 한다.
element : React element, type
과 prop
을 가지는 React 객체를 의미한다.
이 두 가지 type에 isRequired option을 줄 수 있다.
Component.propTypes = { children: PropTypes.element.isRequired }
이러면
단 하나
의 element나 node를 갖는 것을 의미한다.
추가!
elementType : Component element : <Component/>