[英]Warning: Failed prop type: Game: prop type `game` is invalid; it must be a function, usually from React.PropTypes
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// import UI components
import GameList from '../components/game/GameList';
// import actions
import gameActions from '../actions/game';
const Game = (props) => {
const { game, actions } = props;
return (
<GameList game={game} actions={actions} />
);
};
Game.propTypes = {
game: PropTypes.shape.isRequired,
actions: PropTypes.shape.isRequired,
};
function mapStateToProps(state) {
return {
game: state.game,
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(gameActions, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Game);
I am trying to pass these two props as objects to a component and I am getting the invalid prop type error. 我试图将这两个道具作为对象传递给组件,我得到无效的道具类型错误。
I need these two props to be objects, and I am pretty sure they are objects, why it needs them to be function? 我需要这两个道具作为对象,我很确定它们是对象,为什么它需要它们才能起作用?
The issue lies in your propTypes definition: 问题在于propTypes定义:
Game.propTypes = {
game: PropTypes.shape.isRequired,
actions: PropTypes.shape.isRequired,
};
for each you should be doing: PropTypes.shape({}).isRequired
or PropTypes.object.isRequired
对于你应该做的每一个:
PropTypes.shape({}).isRequired
或PropTypes.object.isRequired
by just doing shape
it's passing the shape function as the expectation. 通过
shape
它将形状函数作为期望传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.