UNPKG

1.39 kBTypeScriptView Raw
1import type * as PropTypes from "prop-types";
2import { Component, ComponentClass, ComponentLifecycle, ReactNode } from "react";
3
4declare namespace createReactClass {
5 interface Mixin<P, S> extends ComponentLifecycle<P, S> {
6 mixins?: Array<Mixin<P, S>> | undefined;
7 statics?: {
8 [key: string]: any;
9 } | undefined;
10
11 displayName?: string | undefined;
12 propTypes?: PropTypes.ValidationMap<any> | undefined;
13 contextTypes?: PropTypes.ValidationMap<any> | undefined;
14 childContextTypes?: PropTypes.ValidationMap<any> | undefined;
15
16 getDefaultProps?(): P;
17 getInitialState?(): S;
18 }
19
20 interface ComponentSpec<P, S> extends Mixin<P, S> {
21 render(): ReactNode;
22
23 [propertyName: string]: any;
24 }
25 interface ClassicComponent<P = {}, S = {}> extends Component<P, S> {
26 replaceState(nextState: S, callback?: () => void): void;
27 isMounted(): boolean;
28 getInitialState?(): S;
29 }
30
31 interface ClassicComponentClass<P = {}> extends Omit<ComponentClass<P>, "new"> {
32 new(props: P, context?: any): ClassicComponent<P, any>;
33 getDefaultProps?(): P;
34 }
35}
36declare function createReactClass<P, S = {}>(
37 spec: createReactClass.ComponentSpec<P, S>,
38): createReactClass.ClassicComponentClass<P>;
39
40export as namespace createReactClass;
41export = createReactClass;