Closed ambewas closed 6 years ago
Thanks for the PR, but we explicitly discourage from giving PropTypes runtime semantics beyond DEV-time validation of React props. Partially because it lets people safely remove declarations in the production builds without worrying if other libs read them.
If you need something more powerful, coming up with your own separate system would be the best option.
This PR introduces
getPropTypeDefinitions
on the prop-types package.what?
getPropTypeDefinitions
can be called in development, to return an object containing all the prop types defined on a specific component, along with an array of expected values (forenum
types orinstance
's).why?
Being able to call
getPropTypeDefinitions
is especially useful in some higher order components.My own use case is for a wireframing tool that uses actual react-components as building blocks. In one of the higher order components, I need access to the different props of a wrapped component so they can be exposed in a UI, to allow editing of these props and reviewing the changes in real time.
This functionality could also be useful for react dev-tools to allow better insight in props and expected props.
example