Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with using object as a PropType?

I see that Airbnb's style guide includes forbid-prop-types for type object. (as can be seen here)

Can someone explain why I would want to forbid the use of PropType.object?

Is it just that it's too vague? And if so, how can I be more specific?

like image 290
sfletche Avatar asked Dec 13 '25 00:12

sfletche


1 Answers

Is it just that it's too vague?

Yes

And if so, how can I be more specific?

Basically, they're saying if you use object you should really be using shape so you can specify what the key/values of the object are.

 // An object taking on a particular shape
  myObject: React.PropTypes.shape({
    color: React.PropTypes.string,
    fontSize: React.PropTypes.number
  }),
like image 91
Jack Avatar answered Dec 14 '25 12:12

Jack