-
Notifications
You must be signed in to change notification settings - Fork 356
Add support of instanceOf
for functional components or create new componentOf
check
#327
Comments
I would definitely appreciate that! |
It sounds like what you're asking for is a However, Can you elaborate more on what exactly you're having trouble propTyping? |
@ljharb I will show it on an example. Let have three components
Example of usage of those components in valid state:
Example of usage of those components in invalid state because Toolbar cannot contain
The problem is that we want to be able to check whether If it is not possible yet, I would like to implement new check (e.g.
I believe that it can be implemented via This new check would allow developers to restrict which children can component accept by their names. This is pretty simple example but there can be complicated hierarchies of components. I am calling it Thank you @ljharb for your time. I appreciate that and I hope I have described it better. |
Since in this case, you're accepting elements and not components, you'd want to use |
Our team is missing support of
instanceOf(type)
for functional components. Motivation is that you can have parental component (e.g.Toolbar
) that can only accept several components (e.g.ToolbarGroup
andToolbarItem
). It is possible to check prop types when those components are implemented as classes, but not when they are implemented as function.I have discovered that both class and functional components have its name stored in one variable:
It means that it should be possible to extend existing
instanceOf(type)
check to work with functional components or implement new one. I would prefer to implement new one because it would use different mechanism of detecting its name. It could be called for examplecomponentOf
- or you can suggest another name.I can create pull request with this issue, but the question is if community and Facebook team want this new check.
The text was updated successfully, but these errors were encountered: