Leon Gaban
Leon Gaban

Reputation: 39028

How to check key of prop object from array in React?

With the following code I can check the type of the incoming props, however how do I check the internals of each object inside of the array assets?

AssetsTable.propTypes = {
    assets: PropTypes.array.isRequired
}

Say for example if I wanted to check assets[0].id: PropTypes.string.isRequired

enter image description here

Upvotes: 0

Views: 412

Answers (1)

Tyler Sebastian
Tyler Sebastian

Reputation: 9458

I think you can do something like

React.PropTypes.arrayOf(
  React.PropTypes.shape({
    id: React.PropTypes.string.isRequired
  })
).isRequired

see here for more information

Upvotes: 4

Related Questions