-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Add PropTypes.component to demand a single React component. #857
Conversation
👍 This could probably replace over most usages of |
I'll follow up once this is committed. |
componentName | ||
); | ||
} | ||
return createChainableTypeChecker(validateComponentType).isRequired; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these by default be without isRequired
, for example if a component takes many sub components conditionally in different props (so some can be undefined or null?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense for normal props. I included it because if you use it for children
you most likely always require that the child is present and if you forget isRequired there it sucks. But you are right in that I should probably remove it and leave it up to the developer.
Alright, changed it to not be required by default. |
Even though the code is marked |
The docs state: "Anything that can be rendered: numbers, strings, components or an array containing these types." and explicitly excludes objects. However, some code like this:
will yield something like this:
Should the docs be updated to reflect that objects are also renderable? |
This is a pre-req to construct reactive scopes in #857. "Value blocks" such as `for` init/test/update and `while` test need to be consistently wrapped in enter/leave calls so that we can extend the range of values properly. We also need to handle `for` init blocks a bit differently, since they allow variable declarations but not other types of statements. This PR ensures that we use consistent methods for handling value blocks (`for` test/update and `while` test) and treats `for` init as a new type with its own enter/append/leave visitor functions.
This is super useful for components that wrap a single child, see the test that defines 'children: Props.component'.