Merge pull request #12590 from Chudesnov/stateless-components-children

Allow children in stateless components’ props by default
This commit is contained in:
John Reilly
2016-11-10 09:58:38 +00:00
committed by GitHub
3 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -201,7 +201,7 @@ declare namespace React {
type SFC<P> = StatelessComponent<P>;
interface StatelessComponent<P> {
(props: P, context?: any): ReactElement<any>;
(props: P & { children?: ReactNode }, context?: any): ReactElement<any>;
propTypes?: ValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: P;
+4
View File
@@ -152,6 +152,10 @@ StatelessComponent2.defaultProps = {
foo: 42
};
var StatelessComponent3: React.SFC<SCProps> =
// allows usage of props.children
props => React.DOM.div(null, props.foo, props.children);
// React.createFactory
var factory: React.CFactory<Props, ModernComponent> =
React.createFactory(ModernComponent);
+10
View File
@@ -13,3 +13,13 @@ StatelessComponent.defaultProps = {
};
<StatelessComponent />;
var StatelessComponent2: React.SFC<SCProps> = ({ foo, children }) => {
return <div>{ foo }{ children }</div>;
};
StatelessComponent2.displayName = "StatelessComponent4";
StatelessComponent2.defaultProps = {
foo: 42
};
<StatelessComponent2>24</StatelessComponent2>;