import React from 'react'
// prop-types 里面有各种各样的内置的效验规则
import PropTypes from 'prop-types'
function Test ({list}) {
return (
{list.map(item =>
{item}
)}
)
}
Test.propTypes = { // 这里的 propTypes 首字母要小写
// 定义各种规则
// 给 Test 的 list 数组定义规则
list: PropTypes.array.isRequired // 限定这里的 list 参数的类型必须是数组类型,添加了 isRequired 就是必填项的意思,没填会报错
}
class App extends React.Component {
render () {
return (
)
}
}
export default App