JoeTidee JoeTidee - 5 months ago 27
React JSX Question

In React, how do you check props using PropTypes when the props are namespaced?

I am passing props to a component in this way:

let obj = {
id: someId,
name: someName

<SomeComponent obj={obj} />

I want to be able to use
to check the props entering into
, for example:

SomeComponent.propTypes = { PropTypes.number, PropTypes.string

but the above syntax is not accepted - how is this accomplished?


Use PropTypes.shape for this purpose.

SomeComponent.propTypes = {
    obj : React.Proptypes.shape({
       id: React.PropTypes.number,
       name: React.PropTypes.string