React-redux: Invalid prop type Object for an Array

Created on 27 Jul 2016  路  1Comment  路  Source: reduxjs/react-redux

I have a reducer which returns an array of slides.
const initialState = { slides: [] };

I have added a PropType of Array in the component.
Homepage.propTypes = { slides: React.PropTypes.array };

The problem is that I receive this warning when the component gets rendered. However I am returning array from the reducer.

Warning: Failed prop type: Invalid prop slides of type object supplied to Slider, expected array.

screen shot 2016-07-27 at 17 48 47

I checked in console and when the component is rendered the first time it receives an object of type List in slides prop but after the data is fetched from API it then displays array.

What should I do to remove this warning?

Most helpful comment

This is a usage question, and really not even related to React Redux at all - it's React-specific.

That said, I suppose you could do something like PropTypes.oneOf([PropTypes.array, PropTypes.object]) or something. There's also a third-party package of PropTypes types for Immutable data structures out there that you could use with this as well.

>All comments

This is a usage question, and really not even related to React Redux at all - it's React-specific.

That said, I suppose you could do something like PropTypes.oneOf([PropTypes.array, PropTypes.object]) or something. There's also a third-party package of PropTypes types for Immutable data structures out there that you could use with this as well.

Was this page helpful?
0 / 5 - 0 ratings