matt-p matt-p - 1 year ago 150
React JSX Question

React Proptypes - stateless components

<div className="dm-inbox-item__project">{props.message.project}</div>

I am trying to set out the propTypes within a stateless component, and wish to define propTypes for the properties on message. Currently, I have only been successful in defining the whole message.

InboxItem.propTypes = {
message: PropTypes.string.isRequired,

I would like to do something like the below in order to validate individually.

Inbox.propTypes = {
message.project: Proptypes.string.isRequired,

Any thoughts would be appreciated.

Answer Source

You can do that with React.PropTypes.shape.

Inbox.propTypes = {
    message: React.PropTypes.shape({
      project: React.PropTypes.string.isRequired
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download