JoeTidee JoeTidee - 1 year ago 83
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?

Answer Source

Use PropTypes.shape for this purpose.

SomeComponent.propTypes = {
    obj : React.Proptypes.shape({
       id: React.PropTypes.number,
       name: React.PropTypes.string
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download