每当我使用编辑器发出任何操作时,我都会收到此错误。
warning.js?8a56:35 Warning: Failed prop type: Invalid prop `forumCard` of type `object` supplied to `ForumCard`, expected `array`.
in ForumCard (created by Connect(ForumCard))
in Connect(ForumCard) (created by RouterContext)
in div (created by View)
in View (created by Navigation)
in div (created by View)
in View (created by Navigation)
in MuiThemeProvider (created by Navigation)
in Navigation (created by WithWidth)
in EventListener (created by WithWidth)
in WithWidth (created by Connect(WithWidth))
in Connect(WithWidth) (created by Authentication)
in Authentication (created by Connect(Authentication))
in Connect(Authentication) (created by RouterContext)
in RouterContext (created by Router)
in Router
in Provider
这是我的组件
import React, {Component, PropTypes} from 'react';
import autobind from 'class-autobind';
import {Table, Row, Cell} from 'react-responsive-table';
import {Link} from 'react-router';
import View from '../components/View';
import styles from './ForumCard-style';
export default class ForumCard extends Component {
constructor() {
super(...arguments);
autobind(this);
this.state = {
dateUpdateTopic: new Date(),
forumCardErrorAlertIsShown: false,
};
}
componentWillMount() {
this.props.onFetchForumCard();
}
render() {
return (
<View>
<Table style={styles.padding} material>
<Row header key="row1">
<Cell key="cell1"><Link to="/forum/topic-detail">Topik</Link></Cell>
<Cell key="cell2">Penulis</Cell>
<Cell key="cell3">Komentar</Cell>
<Cell key="cell4">Favorit</Cell>
</Row>
</Table>
</View>
);
}
}
ForumCard.propTypes = {
onFetchForumCard: PropTypes.func,
forumCard: PropTypes.array,
};
这是我的容器
import {connect} from 'react-redux';
import ForumCard from '../components/ForumCard';
export function mapStateToProps(state) {
let {forumCard} = state;
return {
forumCard,
};
}
export function mapDispatchToProps(dispatch) {
return {
onFetchForumCard() {
dispatch({type: 'FETCH_FORUM_CARD_REQUESTED'});
},
};
}
export default connect(mapStateToProps, mapDispatchToProps)(ForumCard);
答案 0 :(得分:0)
您已将propType
forumCard
指定为数组,而其类型将变为object
。确保forumCard
为array
。或者,如果您打算将其作为对象,则将propType更改为Object
ForumCard.propTypes = {
onFetchForumCard: PropTypes.func,
forumCard: PropTypes.object,
};