;
- getDerivedStateFromProps?(
- props: Readonly,
- state: Readonly
- ): Partial | null;
- getDerivedStateFromError?(error: any): Partial | null;
-}
-export interface ComponentConstructor
- extends ComponentClass
{}
-
-// Type alias for a component instance considered generally, whether stateless or stateful.
-export type AnyComponent
=
- | FunctionComponent
- | ComponentConstructor
;
-
-export interface Component
{
- componentWillMount?(): void;
- componentDidMount?(): void;
- componentWillUnmount?(): void;
- getChildContext?(): object;
- componentWillReceiveProps?(nextProps: Readonly
, nextContext: any): void;
- shouldComponentUpdate?(
- nextProps: Readonly
,
- nextState: Readonly,
- nextContext: any
- ): boolean;
- componentWillUpdate?(
- nextProps: Readonly
,
- nextState: Readonly,
- nextContext: any
- ): void;
- getSnapshotBeforeUpdate?(oldProps: Readonly
, oldState: Readonly): any;
- componentDidUpdate?(
- previousProps: Readonly
,
- previousState: Readonly,
- snapshot: any
- ): void;
- componentDidCatch?(error: any, errorInfo: ErrorInfo): void;
-}
-
-export abstract class Component
{
- constructor(props?: P, context?: any);
-
- static displayName?: string;
- static contextType?: Context;
-
- // Static members cannot reference class type parameters. This is not
- // supported in TypeScript. Reusing the same type arguments from `Component`
- // will lead to an impossible state where one cannot satisfy the type
- // constraint under no circumstances, see #1356.In general type arguments
- // seem to be a bit buggy and not supported well at the time of this
- // writing with TS 3.3.3333.
- static getDerivedStateFromProps?(
- props: Readonly,
- state: Readonly
- ): object | null;
- static getDerivedStateFromError?(error: any): object | null;
-
- state: Readonly;
- props: RenderableProps ;
- context: any;
- base?: Element | Text;
-
- // From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
- // // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
- // // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
- setState(
- state:
- | ((
- prevState: Readonly,
- props: Readonly
- ) => Pick | Partial | null)
- | (Pick | Partial | null),
- callback?: () => void
- ): void;
-
- forceUpdate(callback?: () => void): void;
-
- abstract render(
- props?: RenderableProps
,
- state?: Readonly,
- context?: any
- ): ComponentChild;
-}
-
-//
-// Preact createElement
-// -----------------------------------
-
-export function createElement(
- type: 'input',
- props:
- | (JSXInternal.DOMAttributes &
- ClassAttributes)
- | null,
- ...children: ComponentChildren[]
-): VNode<
- JSXInternal.DOMAttributes &
- ClassAttributes
->;
-export function createElement<
- P extends JSXInternal.HTMLAttributes,
- T extends HTMLElement
->(
- type: keyof JSXInternal.IntrinsicElements,
- props: (ClassAttributes & P) | null,
- ...children: ComponentChildren[]
-): VNode & P>;
-export function createElement<
- P extends JSXInternal.SVGAttributes,
- T extends HTMLElement
->(
- type: keyof JSXInternal.IntrinsicElements,
- props: (ClassAttributes & P) | null,
- ...children: ComponentChildren[]
-): VNode & P>;
-export function createElement(
- type: string,
- props:
- | (ClassAttributes &
- JSXInternal.HTMLAttributes &
- JSXInternal.SVGAttributes)
- | null,
- ...children: ComponentChildren[]
-): VNode<
- ClassAttributes & JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes
->;
-export function createElement(
- type: ComponentType
| string,
- props: (Attributes & P) | null,
- ...children: ComponentChildren[]
-): VNode
;
-export namespace createElement {
- export import JSX = JSXInternal;
-}
-
-export function h(
- type: 'input',
- props:
- | (JSXInternal.DOMAttributes &
- ClassAttributes)
- | null,
- ...children: ComponentChildren[]
-): VNode<
- JSXInternal.DOMAttributes &
- ClassAttributes
->;
-export function h<
- P extends JSXInternal.HTMLAttributes,
- T extends HTMLElement
->(
- type: keyof JSXInternal.IntrinsicElements,
- props: (ClassAttributes & P) | null,
- ...children: ComponentChildren[]
-): VNode & P>;
-export function h<
- P extends JSXInternal.SVGAttributes,
- T extends HTMLElement
->(
- type: keyof JSXInternal.IntrinsicElements,
- props: (ClassAttributes & P) | null,
- ...children: ComponentChildren[]
-): VNode & P>;
-export function h(
- type: string,
- props:
- | (ClassAttributes &
- JSXInternal.HTMLAttributes &
- JSXInternal.SVGAttributes)
- | null,
- ...children: ComponentChildren[]
-): VNode<
- | (ClassAttributes &
- JSXInternal.HTMLAttributes &
- JSXInternal.SVGAttributes)
- | null
->;
-export function h(
- type: ComponentType
| string,
- props: (Attributes & P) | null,
- ...children: ComponentChildren[]
-): VNode;
-export namespace h {
- export import JSX = JSXInternal;
-}
-
-//
-// Preact render
-// -----------------------------------
-interface ContainerNode {
- readonly nodeType: number;
- readonly parentNode: ContainerNode | null;
- readonly firstChild: ContainerNode | null;
- readonly childNodes: ArrayLike;
-
- insertBefore(node: ContainerNode, child: ContainerNode | null): ContainerNode;
- appendChild(node: ContainerNode): ContainerNode;
- removeChild(child: ContainerNode): ContainerNode;
-}
-
-export function render(vnode: ComponentChild, parent: ContainerNode): void;
-/**
- * @deprecated Will be removed in v11.
- *
- * Replacement Preact 10+ implementation can be found here: https://gist.github.com/developit/f4c67a2ede71dc2fab7f357f39cff28c
- */
-export function render(
- vnode: ComponentChild,
- parent: ContainerNode,
- replaceNode?: Element | Text
-): void;
-export function hydrate(vnode: ComponentChild, parent: ContainerNode): void;
-export function cloneElement(
- vnode: VNode,
- props?: any,
- ...children: ComponentChildren[]
-): VNode;
-export function cloneElement(
- vnode: VNode
,
- props?: any,
- ...children: ComponentChildren[]
-): VNode
;
-
-//
-// Preact Built-in Components
-// -----------------------------------
-
-// TODO: Revisit what the public type of this is...
-export const Fragment: FunctionComponent<{}>;
-
-//
-// Preact options
-// -----------------------------------
-
-/**
- * Global options for preact
- */
-export interface Options {
- /** Attach a hook that is invoked whenever a VNode is created. */
- vnode?(vnode: VNode): void;
- /** Attach a hook that is invoked immediately before a vnode is unmounted. */
- unmount?(vnode: VNode): void;
- /** Attach a hook that is invoked after a vnode has rendered. */
- diffed?(vnode: VNode): void;
- event?(e: Event): any;
- requestAnimationFrame?(callback: () => void): void;
- debounceRendering?(cb: () => void): void;
- useDebugValue?(value: string | number): void;
- _addHookName?(name: string | number): void;
- _afterRender?(newVNode: VNode, oldVNode: VNode): void;
- __suspenseDidResolve?(vnode: VNode, cb: () => void): void;
- // __canSuspenseResolve?(vnode: VNode, cb: () => void): void;
-
- /**
- * Customize attribute serialization when a precompiled JSX transform
- * is used.
- */
- attr?(name: string, value: any): string | void;
-}
-
-export const options: Options;
-
-//
-// Preact helpers
-// -----------------------------------
-export function createRef(): RefObject;
-export function toChildArray(
- children: ComponentChildren
-): Array;
-export function isValidElement(vnode: any): vnode is VNode;
-
-//
-// Context
-// -----------------------------------
-export interface Consumer
- extends FunctionComponent<{
- children: (value: T) => ComponentChildren;
- }> {}
-export interface PreactConsumer extends Consumer {}
-
-export interface Provider
- extends FunctionComponent<{
- value: T;
- children?: ComponentChildren;
- }> {}
-export interface PreactProvider extends Provider {}
-export type ContextType> = C extends Context
- ? T
- : never;
-
-export interface Context {
- Consumer: Consumer;
- Provider: Provider;
- displayName?: string;
-}
-export interface PreactContext extends Context {}
-
-export function createContext(defaultValue: T): Context;