Warning: Failed prop type: Game: prop type `game` is invalid; it must be a function, usually from React.PropTypes

user1070111
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?

James Ganong

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.

edited at
0

Comments

0 comments
Login to comment

Related

Failed prop type: Chat: prop type `room` is invalid; it must be a function, usually from React.PropTypes

React Warning: Failed prop type: Invalid prop of type `Object` supplied

React Warning: "Failed prop type: checker is not a function"

Warning: Failed propType: Invalid prop of type `array` expected `object` with React

Warning: Failed prop type: Invalid prop `defaultValue` of type `string` supplied to `AutoCompleteSearch`, expected `function`

Warning: Failed prop type: Invalid prop `open` of type `function` supplied to `ForwardRef(Dialog)`, expected `boolean`. at Dialog

Warning: Failed prop type: Invalid prop `tag` supplied to `NavLink`

Warning: Failed prop type: Invalid prop 'source' supplied to 'Image'

warning: failed prop type: invalid prop 'backgroundcolor' supplied to view:

Failed prop type: Invalid prop `className` of type 'function'

vue warning: Invalid prop: type check failed for prop "modalState". Expected Boolean, got Function

Warning: failed prop type in React error

React PropTypes import class. Prop type is invalid

React: Prop type must be a function, but received object

Failed prop type: Invalid prop `to` supplied to `Redirect`

Failed prop type: Invalid prop 'value'

it must be a function, usually from React.PropTypes

Warning: Failed prop type: Invalid prop `data` of type `object` supplied to `Carousel`, expected `array`

Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`

GraphQL: Warning: Failed prop type: Invalid prop `query` of type `object` supplied to `StaticQuery`, expected `string`

Warning: Failed prop type: Invalid prop `items[0]` of type `string` supplied to `ImageGallery`, expected `object`

React Native + Icons: Warning: Failed prop type: Invalid props.style key tintColor supplied to ForwardRef(Text)

Getting Warning: Failed propType: Invalid prop of type `array` expected `object` in React

React : Warning: Failed prop type: Cannot read property 'apply' of undefined

Display list of trails in React - "Warning: Failed prop type"

GETTING ERROR : Warning: Failed prop type: Invalid prop `children` supplied to `Form`, expected a ReactNode

Warning: Failed prop type: Invalid prop `source` supplied to `Image`. I have saved path of the image with require() in an object

Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef(Select)`, expected a ReactNode

Invalid prop of type `string` in react