React 함수 인자를 array로 받기에 PropType을
TodoList.propTypes = {
todoList: PropTypes.array.isRequired,
};
으로 설정한다면
Prop type `array` is forbidden
이라는 에러를 접할 것이다.
이 이유는 airbnb eslint에서 금지하고 있기 때문이다. (정확히 말하면 eslint-plugin-react)
Why?
왜냐하면 PropTypes.array는 아래 경우가 모두 해당되기 떄문이다.
- array of objects [{name:'ABC'},{name:'XYZ'}]
- array of strings ['Lorem','Ipsum']
- array of integers [2,4,66,4]
- array of nested arrays [['d'],[[{name:'a'},{name:'b'}]]]
- array of functions [foo,bar]
좀더 구체적으로 타입을 설정해주기 위해서 나같은 경우에는 아래와 같이 설정해줌으로써 에러를 해결할 수 있다.
TodoList.propTypes = {
todoList: PropTypes.arrayOf(PropTypes.object).isRequired,
};
'개발 > Web Programming' 카테고리의 다른 글
[D3.js] 동작방식 (0) | 2021.01.21 |
---|---|
SVG란? (0) | 2021.01.21 |
[Git] git commit log의 용어 정의 (0) | 2021.01.12 |
[React] 리액트에서 key는 꼭 필요할까? (0) | 2021.01.10 |
[React] 리액트는 어떻게 화면을 업데이트 하는가? (0) | 2021.01.10 |