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:
Game.propTypes = {
game: PropTypes.shape.isRequired,
actions: PropTypes.shape.isRequired,
};
for each you should be doing: PropTypes.shape({}).isRequired
or PropTypes.object.isRequired
by just doing shape
it's passing the shape function as the expectation.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments