我有一个容器组件:
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
class MyComponent extends Component {
static propTypes = {
someEntities: PropTypes.object.isRequired
}
....
}
export default connect(state => ({ someEntities: state.someEntities })(MyComponent)
所以我通过connect
将道具传递给这个组件,但当我将组件放在代码中时,如:
....
import MyComponent from './MyComponent';
....
<div><MyComponent /></div>
....
WebStorm突出显示MyComponent
并向我显示错误:Element MyComponent doesn't have required attribute someEntities
。
我使用的是版本2016.3.1。这是一个错误吗?在这种情况下我应该使用propTypes
吗?
答案 0 :(得分:7)