Reputation: 39034
Below is the current error I'm getting:
Here is my current PropTypes code, I need to check if the objects inside of the Array coming in have the following properties (id
and name
).
React.PropTypes.arrayOf(
React.PropTypes.shape({
id: React.PropTypes.string.isRequired,
name: React.PropTypes.string.isRequired
})
).isRequired
Reading here https://github.com/tomchentw/react-google-maps/issues/463 apparently React.PropTypes
is going to be deprecated.
However how would you check the types inside of an Object that is in an Array coming in via the Props with just this logic:
AssetsTable.propTypes = {
asset: PropTypes.object.isRequired,
price_usd: PropTypes.string.isRequired
};
Basically, the Array coming in, has objects which look like this:
Upvotes: 1
Views: 2174
Reputation: 418
Use the prop-types library the same as you would with React. e.g.
import PropTypes from 'prop-types';
class MyComponent extends React.Component {
static propTypes = {
someValue: PropTypes.number
}
}
Upvotes: 0
Reputation: 961
Insted of using React.PropTypes
, first you need to install the prop-types
package (trough npm or your favourite package manager). Then import it with import PropTypes from 'prop-types';
, and then use PropTypes
just as you would React.PropTypes
.
Upvotes: 1
Reputation: 16451
Prop-types supports shape just like React.PropTypes
From the React Docs:
// An object taking on a particular shape
optionalObjectWithShape: PropTypes.shape({
color: PropTypes.string,
fontSize: PropTypes.number
}),
Upvotes: 1