facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Custom component detection prop validation #307

Open bendykstra94 opened 4 years ago

bendykstra94 commented 4 years ago

Hi there!

Is there a way to add custom component detection such that subclasses of a custom component can still get their props validated?

According to https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md#about-component-detection only components that utilize createReactClass(), inherit from React.Component or Component, or are stateless functions can have their props validated.

My use case is that I have a custom base component that almost all of my other components inherit from and would like to have validation done on those components.

If there's a place I could be pointed to to start working on this I'd be happy to!

Thanks so much!

ljharb commented 4 years ago

React strongly discourages any subclassing of components - use composition, not inheritance.

In other words, the entire pattern of having a base component has been discouraged in React for its entire existence.