-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
How to best define a propType for accepting a component as a prop? #5143
Comments
@jimbolla |
@jimbolla This is a usage question rather than a bug in the React core. We use github issues for tracking bugs in the React core. Usage questions are better answered on StackOverflow. Since this is not a bug in the React core, I'm going to close this issue. Feel free to continue the discussion on this thread. |
@yaycmyk That's not I'm looking for.
whereas I want something that would look like:
I want to pass types, not instances. |
|
@zpao Thanks. Would you just use |
This also captures the native element case (eg |
Ok, thank you. |
@zpao This is wrong now. The new context api caused object also maybe a react component. |
|
@nermand no, |
FYI:
does not support components created with |
note: there seems to be no consensus on what the right proptype would be facebook/react#5143 but after looking in node modules, it seems that react-router itself uses func :shrug:
Will isValidElementType of react-is do here? A custom prop validation using Array.isArray() and isValidElementType like this:
|
This is how react-router handles it here:
|
@ZackKnopp That's what I also said. |
@ZackKnopp : Here's a modified version of the validation function that is more generic and that can be reused everywhere:
|
You can now use |
Could someone clarify how |
|
What types of TypeScript do you use to support both? |
I think this is incorrect as per the docs node is something else:
It looks like the correct PropType for react components is
|
Given this contrived example, what is the best definition of
componentType
?The text was updated successfully, but these errors were encountered: