Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

cpojer
Copy link
Contributor

@cpojer cpojer commented Jan 9, 2014

This is super useful for components that wrap a single child, see the test that defines 'children: Props.component'.

@Daniel15
Copy link
Member

Daniel15 commented Jan 9, 2014

👍 This could probably replace over most usages of onlyChild :)

@cpojer
Copy link
Contributor Author

cpojer commented Jan 9, 2014

I'll follow up once this is committed.

componentName
);
}
return createChainableTypeChecker(validateComponentType).isRequired;
Copy link
Contributor

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?)

Copy link
Contributor Author

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.

@cpojer
Copy link
Contributor Author

cpojer commented Jan 9, 2014

Alright, changed it to not be required by default.

@cpojer cpojer closed this Jan 10, 2014
@cpojer cpojer deleted the component-prop branch January 10, 2014 01:02
@plievone
Copy link
Contributor

Even though the code is marked @internal, prop validation is public as React.PropTypes and documented here: https://github.com/facebook/react/blob/338ce60/docs/docs/05-reusable-components.md
Perhaps component type (what about renderable and oneOfType) should be there too?

@awei01
Copy link

awei01 commented May 23, 2014

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:

ReactTestUtils.renderIntoDocument(React.DOM.div(null, { foo: "bar" }))

will yield something like this:

<div data-reactid=".5c"><span data-reactid=".5c.$foo:0">bar</span></div>

Should the docs be updated to reflect that objects are also renderable?

josephsavona added a commit that referenced this pull request May 15, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants