props의 타입1 리액트[기초] propTypes propTypes 이란? 컴포넌트의 필수 props를 지정하거나 props의 타입을 지정할 때 사용한다 propTypes 지정하는 방법 1. 코드 상단에 prop-types를 import 해준다 2. 컴포넌트에서 설정해준다(설정한 값은 전달될 때 무조건 설정한 형태로 전달되어야 한다) // 자식 컴포넌트 import PropTypes from 'prop-types'; const MyComponent = ({ name, children }) => { 생략.. } MyComponent.defaultProps = { name: '기본 이름' }; // name 은 무조건 문자열(string)형태로만 전달해야된다 MyComponent.propTypes = { name: PropTypes.string }; exp.. 2022. 5. 27. 이전 1 다음 728x90