Made create-react-class S(tate) template optional (#39154)

* create-react-class: default state to {}

It's irksome having to always provide a `{}`...

* Added props-without-state test

* Added props declaration to CCC
This commit is contained in:
Josh Goldberg 2019-10-17 17:22:52 -04:00 committed by Andrew Branch
parent fb23b1ef93
commit e7f4d0d913
2 changed files with 7 additions and 1 deletions

View File

@ -79,6 +79,12 @@ const ClassicComponentNoProps: React.ClassicComponentClass = createReactClass({
}
});
const ClassicComponentNoState: React.ClassicComponentClass<{ text: string }> = createReactClass<{ text: string }>({
render() {
return DOM.div(this.props.text);
}
});
// React.createFactory
const classicFactory: React.ClassicFactory<Props> =
React.createFactory(ClassicComponent);

View File

@ -7,7 +7,7 @@
import { ComponentSpec, ClassicComponentClass } from "react";
declare namespace createReactClass {}
declare function createReactClass<P, S>(spec: ComponentSpec<P, S>): ClassicComponentClass<P>;
declare function createReactClass<P, S = {}>(spec: ComponentSpec<P, S>): ClassicComponentClass<P>;
export as namespace createReactClass;
export = createReactClass;