Discern new vs old style components through render

By overloading createElement() for the ClassicComponentClass and
creating a separate ReactClassicElement type, we can keep track of which
calls to render() should create a ClassicComponent versus a new style
Component. Useful for keeping the old API, which makes migration easier.
This commit is contained in:
Hraban Luyat
2015-01-30 06:09:39 +01:00
parent 01ce3ccf7f
commit f6da4b13b8
+5
View File
@@ -17,6 +17,9 @@ declare module React {
ref: string;
}
interface ReactClassicElement<P> extends ReactElement<P> {
}
interface ReactHTMLElement extends ReactElement<HTMLAttributes> {}
interface ReactSVGElement extends ReactElement<SVGAttributes> {}
@@ -112,8 +115,10 @@ declare module React {
interface TopLevelAPI {
createClass<P, S, C>(spec: ComponentSpec<P, S, C>): ClassicComponentClass<P, S, C>;
createElement<P>(type: ClassicComponentClass<P, any, any>, props: P, ...children: ReactNode[]): ReactClassicElement<P>;
createElement<P>(type: ComponentClass<P, any, any> | string, props: P, ...children: ReactNode[]): ReactElement<P>;
createFactory<P>(type: ComponentClass<P, any, any> | string): ComponentFactory<P>;
render<P, S>(element: ReactClassicElement<P>, container: Element, callback?: () => any): ClassicComponent<P, S, any>;
render<P, S>(element: ReactElement<P>, container: Element, callback?: () => any): Component<P, S, any>;
unmountComponentAtNode(container: Element): boolean;
renderToString(element: ReactElement<any>): string;