New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request - PropType.*.name #8310
Comments
If it is OK I can make PR |
Can you please explain why you're testing presence of PropTypes? How is this helping you? Some examples from product code would be helpful. |
Hi @gaearon. Sorry for late response. I will provide few examples when this is feature is useful React storybook and react storybook info addon
Info addon parses all components from story and show table with component prop types and default props. Link to PropTypesMap generation https://github.com/storybooks/react-storybook-addon-info/blob/89bc19038c09b0b3439f5abb8de91315228d47e5/src/components/PropTable.js#L4 So if implement requested feature - this addon will work more correctly and for all prop types. ForgekitForgekit merge prop types and default props from component and components features. I mean:
foo: PropTypes.string
foo: PropTypes.string This case is OK, but:
foo: propTypes.string
foo: propTypes.bool This case is a prop type collision. But now this prop types matching is not reachable. |
btw maybe save autogenerated |
@gaearon any updates?) |
I'm worried that something like |
Provide simple PR with feature implementation. I hope it will be completely clear if look at tests If it is OK - I will complete PR (clean code, remove duplications etc). |
+1 |
This actually sounds like something that will break in future versions of React. You should not be using PropTypes for any behavior that is observable in production. For example, we plan to replace the PropTypes checkers with a single throwing type checker in prod (to reduce React byte size). In this case This is why I’m sceptical about this direction. I don’t want to make PropTypes more powerful because then people will start relying on them to implement “magic” behaviors that we don’t support and could break in the future. |
@gaearon I agree, this direction is probably wrong. But another cases are still useful and only for dev env
Another case from project I have worked with: There a lot of components with complex props. static propTypes = {
strings: PropTypes.shape({
title: PropTypes.string,
subtitle: PropTypes.string,
text: PropTypes.string,
}).
images: PropTypes.shape({
image: PropTypes.object,
}),
options: PropTypes.shape({
backgroundColor: PropTypes.string,
}),
links: PropTypes.shape({
appstore: PropTypes.string,
playmarket: PropTypes.string,
}),
} So to build form at control panel to edit component values developers should read component source as text and then parse prop types. Also it can be implemented via:
PropTypes struct maybe is most suitable solution. And I think there are lot of other examples where this feature would be useful. Anyway this is not really important feature among other React pull requests or other React needs :) |
I want to create a small faker module for React that generates random data based on the components propTypes. This feature would be very helpful, because there is currently no "native" solution to handle this problem in a comfortable way. You can look at my current idea of implementation here: oleblaesing/react-proptypes-faker |
PropTypes have been removed from React core and now exist as a separate package |
Feature request: Fill name attribute or add static toString() method for all PropTypes.
For example:
It maybe useful when debugging.
In my case - I need to equal components prop types and throw exception if there are same props. So if generate names for prop types - they could be compared.
Current behaviour
Only primitive types could be compared (string, bool, number).
Complex types (shape, arrayOf) - each time returns new bound function. So it could not be compared by value.
Problems with custom prop types
Will generate "undefined" name for custom prop like this:
but it fixed by adding function name:
btw. Same feature implemented at tcomb lib
The text was updated successfully, but these errors were encountered: