Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- padding 속성
- id 선택자
- iframe 태그
- Live Server
- br 태그
- 인접 형제 결합자
- sup태그
- sub태그
- i 태그
- 임베디드
- RGB
- go live
- css
- 전체 선택자
- html tag i
- iframe
- focus 의사클래스
- html 태그
- RGBA
- width속성
- reveal in file explorer
- 아두이노
- tag html
- height속성
- html
- not 의사클래스
- background-color 속성
- 자식결합자
- Checked 의사 클래스
- 일반 형제 결합자
Archives
- Today
- Total
so woon!
[React] propTypes 설치하기 본문
학습일 : 2023. 03. 16
터미널창에
npm i prop-types 를 입력하고 엔터를 하면 설치가 된다.
위 방법을 실행했을 경우 어떠한 에러가 난다면
터미널창에
1. npm install --global yarn 엔터
2. yarn add prop-types 엔터
하여 설치가 정상적으로 완료된다면
이제 PropTypes를 import 할 수 있는 상태가 된다.
그럼 import 하여 PropTypes를 사용해보도록 하자.
import PropTypes from "prop-types";
를 상단에 적어준다.
이렇게 import 해주면 밑에서 사용할 수 있는 상태가 된다.
전체 코드
Button.propTypes = {...}
이렇게 작성하여 사용할 수 있다.
import PropTypes from "prop-types";
function Button({text}) {
return <button>{text}</button>;
}
Button.propTypes = {
text: PropTypes.string.isRequired,
}
export default Button;
이렇게 propTypes를 사용하여 text의 경우 string 타입이고 필수라는 조건을 주었기 때문에
리액트가 Button의 경우 그런 조건에 어긋날 경우 경고를 해줄 수 있게 된다.
'ReactJS > 개념정리' 카테고리의 다른 글
[React] 동일한 css 속성을 다른 파일 내에서 사용하기 (0) | 2023.03.16 |
---|---|
[React] CSS 적용하기 (0) | 2023.03.16 |
[React] 관계성 살펴보기 (0) | 2023.03.16 |
[React] import (0) | 2023.03.15 |
[React] create-react-app (0) | 2023.03.15 |
Comments