├── .babelrc
├── .eslintignore
├── .eslintrc.js
├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── .husky
└── pre-commit
├── .npmrc
├── .prettierignore
├── .prettierrc.js
├── LICENSE
├── example
├── App.vue
├── components
│ ├── dnd.vue
│ ├── json.vue
│ └── markdown.vue
├── files.d.ts
├── index.html
├── index.tsx
├── kbar.ts
├── react-input.ts
├── react-props.ts
├── tsconfig.json
├── types.d.ts
└── xlog.tsx
├── package.json
├── pnpm-lock.yaml
├── readme.md
├── renovate.json
├── rollup.config.js
├── src
├── global.d.ts
├── index.ts
├── libs
│ ├── react-dom.ts
│ └── react.ts
├── react-types
│ └── react
│ │ ├── package.json
│ │ └── react.d.ts
├── tsconfig.build.json
├── tsconfig.cjs.json
├── tsconfig.json
├── utils
│ └── index.ts
└── wrapper.ts
├── tsconfig.json
├── vite.config.js
└── vitest.config.ts
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | // if need react
4 | // "@babel/preset-react"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | src/react-types/**
2 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: {
4 | browser: true,
5 | node: true,
6 | es6: true,
7 | },
8 | extends: ['@innei-util/eslint-config-react-ts'],
9 | }
10 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3 |
4 | name: Node.js CI
5 |
6 | on:
7 | push:
8 | branches: [master]
9 | pull_request:
10 | branches: [master]
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 |
16 | strategy:
17 | matrix:
18 | node-version: [14.x, 16.x]
19 |
20 | steps:
21 | - uses: actions/checkout@v2
22 | - name: Use Node.js ${{ matrix.node-version }}
23 | uses: actions/setup-node@v2
24 | with:
25 | node-version: ${{ matrix.node-version }}
26 | - name: Cache pnpm modules
27 | uses: actions/cache@v2
28 | env:
29 | cache-name: cache-pnpm-modules
30 | with:
31 | path: ~/.pnpm-store
32 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
33 | restore-keys: |
34 | ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
35 |
36 | - uses: pnpm/action-setup@v2.0.1
37 | with:
38 | version: 6.0.2
39 | run_install: true
40 | - run: pnpm run package
41 | - run: pnpm run test
42 | env:
43 | CI: true
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | tags
2 | node_modules
3 | /node_modules
4 | .DS_Store
5 | # Logs
6 | logs
7 | *.log
8 | npm-debug.log*
9 | yarn-debug.log*
10 | yarn-error.log*
11 | lerna-debug.log*
12 |
13 | # Diagnostic reports (https://nodejs.org/api/report.html)
14 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15 |
16 | # Runtime data
17 | pids
18 | *.pid
19 | *.seed
20 | *.pid.lock
21 |
22 | # Directory for instrumented libs generated by jscoverage/JSCover
23 | lib-cov
24 |
25 | # Coverage directory used by tools like istanbul
26 | coverage
27 | *.lcov
28 |
29 | # nyc test coverage
30 | .nyc_output
31 |
32 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33 | .grunt
34 |
35 | # Bower dependency directory (https://bower.io/)
36 | bower_components
37 |
38 | # node-waf configuration
39 | .lock-wscript
40 |
41 | # Compiled binary addons (https://nodejs.org/api/addons.html)
42 | build/Release
43 |
44 | # Dependency directories
45 | node_modules/
46 | jspm_packages/
47 |
48 | # Snowpack dependency directory (https://snowpack.dev/)
49 | web_modules/
50 |
51 | # TypeScript cache
52 | *.tsbuildinfo
53 |
54 | # Optional npm cache directory
55 | .npm
56 |
57 | # Optional eslint cache
58 | .eslintcache
59 |
60 | # Microbundle cache
61 | .rpt2_cache/
62 | .rts2_cache_cjs/
63 | .rts2_cache_es/
64 | .rts2_cache_umd/
65 |
66 | # Optional REPL history
67 | .node_repl_history
68 |
69 | # Output of 'npm pack'
70 | *.tgz
71 |
72 | # Yarn Integrity file
73 | .yarn-integrity
74 |
75 | # parcel-bundler cache (https://parceljs.org/)
76 | .cache
77 | .parcel-cache
78 |
79 | # Next.js build output
80 | .next
81 |
82 | # Nuxt.js build / generate output
83 | .nuxt
84 |
85 | # Gatsby files
86 | .cache/
87 |
88 | # vuepress build output
89 | .vuepress/dist
90 |
91 | # Serverless directories
92 | .serverless/
93 |
94 | # FuseBox cache
95 | .fusebox/
96 |
97 | # DynamoDB Local files
98 | .dynamodb/
99 |
100 | # TernJS port file
101 | .tern-port
102 |
103 | # Stores VSCode versions used for testing VSCode extensions
104 | .vscode-test
105 |
106 | # yarn v2
107 |
108 | .yarn/cache
109 | .yarn/unplugged
110 | .yarn/build-state.yml
111 | .pnp.*
112 |
113 | # vim
114 | ctag
115 | /tags
116 | .undodir
117 |
118 | # idea
119 | # .idea/*
120 |
121 | /dist
122 | /publish
123 | /build
124 | /lib
125 | /esm
126 | /types
127 |
128 | example/dist
129 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | lint-staged
5 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | registry=https://registry.npmjs.org
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | src/react-types/**
2 |
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = require('@innei-util/prettier')
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Innei
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/example/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | React Button This is Vue component
5 |
6 |
8 | TestInput
9 |
11 |
12 |
22 |
23 |
= 74 | { 75 | [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K] ? K : never 76 | }[keyof JSX.IntrinsicElements] | 77 | ComponentType
; 78 | /** 79 | * @deprecated Please use `ElementType` 80 | */ 81 | type ReactType
= ElementType
; 82 | type ComponentType
= ComponentClass
| FunctionComponent
; 83 | 84 | type JSXElementConstructor
=
85 | | ((props: P) => ReactElement );
87 |
88 | interface RefObject = string | JSXElementConstructor > { }
156 |
157 | /**
158 | * @deprecated Please use `FunctionComponentElement`
159 | */
160 | type SFCElement = FunctionComponentElement ;
161 |
162 | interface FunctionComponentElement extends ReactElement > {
163 | ref?: ('ref' extends keyof P ? P extends { ref?: infer R | undefined } ? R : never : never) | undefined;
164 | }
165 |
166 | type CElement > = ComponentElement ;
167 | interface ComponentElement > extends ReactElement > {
168 | ref?: LegacyRef = CElement >;
172 |
173 | // string fallback for custom web-components
174 | interface DOMElement | SVGAttributes {
175 | ref: LegacyRef , T extends HTMLElement> extends DOMElement {
182 | type: keyof ReactHTML;
183 | }
184 |
185 | // ReactSVG for ReactSVGElement
186 | interface ReactSVGElement extends DOMElement = (props?: Attributes & P, ...children: ReactNode[]) => ReactElement ;
200 |
201 | /**
202 | * @deprecated Please use `FunctionComponentFactory`
203 | */
204 | type SFCFactory = FunctionComponentFactory ;
205 |
206 | type FunctionComponentFactory = (props?: Attributes & P, ...children: ReactNode[]) => FunctionComponentElement ;
207 |
208 | type ComponentFactory > =
209 | (props?: ClassAttributes ;
210 |
211 | type CFactory > = ComponentFactory ;
212 | type ClassicFactory = CFactory >;
213 |
214 | type DOMFactory , T extends Element> =
215 | (props?: ClassAttributes ;
216 |
217 | interface HTMLFactory , T extends HTMLElement> extends DOMFactory {
220 | (props?: ClassAttributes ;
221 | }
222 |
223 | interface SVGFactory extends DOMFactory , T extends Element>(
249 | type: string): DOMFactory ;
250 |
251 | // Custom components
252 | function createFactory (type: FunctionComponent ): FunctionComponentFactory ;
253 | function createFactory (
254 | type: ClassType , ClassicComponentClass >): CFactory >;
255 | function createFactory , C extends ComponentClass >(
256 | type: ClassType ): CFactory ;
257 | function createFactory (type: ComponentClass ): Factory ;
258 |
259 | // DOM Elements
260 | // TODO: generalize this to everything in `keyof ReactHTML`, not just "input"
261 | function createElement(
262 | type: "input",
263 | props?: InputHTMLAttributes , T extends HTMLElement>(
266 | type: keyof ReactHTML,
267 | props?: ClassAttributes ;
269 | function createElement , T extends SVGElement>(
270 | type: keyof ReactSVG,
271 | props?: ClassAttributes , T extends Element>(
274 | type: string,
275 | props?: ClassAttributes ;
277 |
278 | // Custom components
279 |
280 | function createElement (
281 | type: FunctionComponent ,
282 | props?: Attributes & P | null,
283 | ...children: ReactNode[]): FunctionComponentElement ;
284 | function createElement (
285 | type: ClassType , ClassicComponentClass >,
286 | props?: ClassAttributes >;
288 | function createElement , C extends ComponentClass >(
289 | type: ClassType ,
290 | props?: ClassAttributes ;
292 | function createElement (
293 | type: FunctionComponent | ComponentClass | string,
294 | props?: Attributes & P | null,
295 | ...children: ReactNode[]): ReactElement ;
296 |
297 | // DOM Elements
298 | // ReactHTMLElement
299 | function cloneElement , T extends HTMLElement>(
300 | element: DetailedReactHTMLElement ,
301 | props?: P,
302 | ...children: ReactNode[]): DetailedReactHTMLElement ;
303 | // ReactHTMLElement, less specific
304 | function cloneElement , T extends HTMLElement>(
305 | element: ReactHTMLElement , T extends SVGElement>(
310 | element: ReactSVGElement,
311 | props?: P,
312 | ...children: ReactNode[]): ReactSVGElement;
313 | // DOM Element (has to be the last, because type checking stops at first overload that fits)
314 | function cloneElement , T extends Element>(
315 | element: DOMElement ,
316 | props?: DOMAttributes ;
318 |
319 | // Custom components
320 | function cloneElement (
321 | element: FunctionComponentElement ,
322 | props?: Partial & Attributes,
323 | ...children: ReactNode[]): FunctionComponentElement ;
324 | function cloneElement >(
325 | element: CElement ,
326 | props?: Partial & ClassAttributes ;
328 | function cloneElement (
329 | element: ReactElement ,
330 | props?: Partial & Attributes,
331 | ...children: ReactNode[]): ReactElement ;
332 |
333 | // Context via RenderProps
334 | interface ProviderProps {
354 | /**
355 | * **NOTE**: Exotic components are not callable.
356 | */
357 | (props: P): (ReactElement|null);
358 | readonly $$typeof: symbol;
359 | }
360 |
361 | interface NamedExoticComponent extends ExoticComponent {
362 | displayName?: string | undefined;
363 | }
364 |
365 | interface ProviderExoticComponent extends ExoticComponent {
366 | propTypes?: WeakValidationMap | undefined;
367 | }
368 |
369 | type ContextType (object: {} | null | undefined): object is ReactElement ;
387 |
388 | const Children: ReactChildren;
389 | const Fragment: ExoticComponent<{ children?: ReactNode | undefined }>;
390 | const StrictMode: ExoticComponent<{ children?: ReactNode | undefined }>;
391 |
392 | interface SuspenseProps {
393 | children?: ReactNode | undefined;
394 |
395 | /** A fallback react tree to show when a Suspense child (like React.lazy) suspends */
396 | fallback: NonNullable extends ComponentLifecycle { }
433 | class Component {
434 | // tslint won't let me format the sample code in a way that vscode likes it :(
435 | /**
436 | * If set, `this.context` will be set at runtime to the current value of the given Context.
437 | *
438 | * Usage:
439 | *
440 | * ```ts
441 | * type MyContext = number
442 | * const Ctx = React.createContext | P);
476 | /**
477 | * @deprecated
478 | * @see https://reactjs.org/docs/legacy-context.html
479 | */
480 | constructor(props: P, context: any);
481 |
482 | // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
483 | // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
484 | // Also, the ` | S` allows intellisense to not be dumbisense
485 | setState ) => (Pick & Readonly<{ children?: ReactNode | undefined }>;
499 | state: Readonly extends Component { }
510 |
511 | interface ClassicComponent extends Component {
512 | replaceState(nextState: S, callback?: () => void): void;
513 | isMounted(): boolean;
514 | getInitialState?(): S;
515 | }
516 |
517 | interface ChildContextProvider = FunctionComponent ;
532 |
533 | /**
534 | * @deprecated as of recent React versions, function components can no
535 | * longer be considered 'stateless'. Please use `FunctionComponent` instead.
536 | *
537 | * @see [React Hooks](https://reactjs.org/docs/hooks-intro.html)
538 | */
539 | type StatelessComponent = FunctionComponent ;
540 |
541 | type FC = FunctionComponent ;
542 |
543 | interface FunctionComponent {
544 | (props: PropsWithChildren , context?: any): ReactElement | undefined;
546 | contextTypes?: ValidationMap | undefined;
548 | displayName?: string | undefined;
549 | }
550 |
551 | type VFC = VoidFunctionComponent ;
552 |
553 | interface VoidFunctionComponent {
554 | (props: P, context?: any): ReactElement | undefined;
556 | contextTypes?: ValidationMap | undefined;
558 | displayName?: string | undefined;
559 | }
560 |
561 | type ForwardedRef , ref: ForwardedRef extends StaticLifecycle {
585 | new (props: P, context?: any): Component ;
586 | propTypes?: WeakValidationMap | undefined;
587 | contextType?: Context | undefined;
591 | displayName?: string | undefined;
592 | }
593 |
594 | interface ClassicComponentClass extends ComponentClass {
595 | new (props: P, context?: any): ClassicComponent ;
596 | getDefaultProps?(): P;
597 | }
598 |
599 | /**
600 | * We use an intersection type to infer multiple type parameters from
601 | * a single argument, which is useful for many top-level API defs.
602 | * See https://github.com/Microsoft/TypeScript/issues/7234 for more info.
603 | */
604 | type ClassType , C extends ComponentClass > =
605 | C &
606 | (new (props: P, context?: any) => T);
607 |
608 | //
609 | // Component Specs and Lifecycle
610 | // ----------------------------------------------------------------------
611 |
612 | // This should actually be something like `Lifecycle | DeprecatedLifecycle `,
613 | // as React will _not_ call the deprecated lifecycle methods if any of the new lifecycle
614 | // methods are present.
615 | interface ComponentLifecycle extends NewLifecycle , DeprecatedLifecycle {
616 | /**
617 | * Called immediately after a component is mounted. Setting state here will trigger re-rendering.
618 | */
619 | componentDidMount?(): void;
620 | /**
621 | * Called to determine whether the change in props and state should trigger a re-render.
622 | *
623 | * `Component` always returns true.
624 | * `PureComponent` implements a shallow comparison on props and state and returns true if any
625 | * props or states have changed.
626 | *
627 | * If false is returned, `Component#render`, `componentWillUpdate`
628 | * and `componentDidUpdate` will not be called.
629 | */
630 | shouldComponentUpdate?(nextProps: Readonly , nextState: Readonly {
645 | getDerivedStateFromProps?: GetDerivedStateFromProps | undefined;
646 | getDerivedStateFromError?: GetDerivedStateFromError | undefined;
647 | }
648 |
649 | type GetDerivedStateFromProps =
650 | /**
651 | * Returns an update to a component's state based on its new props and old state.
652 | *
653 | * Note: its presence prevents any of the deprecated lifecycle methods from being invoked
654 | */
655 | (nextProps: Readonly , prevState: S) => Partial =
658 | /**
659 | * This lifecycle is invoked after an error has been thrown by a descendant component.
660 | * It receives the error that was thrown as a parameter and should return a value to update state.
661 | *
662 | * Note: its presence prevents any of the deprecated lifecycle methods from being invoked
663 | */
664 | (error: any) => Partial {
668 | /**
669 | * Runs before React applies the result of `render` to the document, and
670 | * returns an object to be given to componentDidUpdate. Useful for saving
671 | * things such as scroll position before `render` causes changes to it.
672 | *
673 | * Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated
674 | * lifecycle events from running.
675 | */
676 | getSnapshotBeforeUpdate?(prevProps: Readonly , prevState: Readonly , prevState: Readonly {
686 | /**
687 | * Called immediately before mounting occurs, and before `Component#render`.
688 | * Avoid introducing any side-effects or subscriptions in this method.
689 | *
690 | * Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps
691 | * prevents this from being invoked.
692 | *
693 | * @deprecated 16.3, use componentDidMount or the constructor instead; will stop working in React 17
694 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
695 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
696 | */
697 | componentWillMount?(): void;
698 | /**
699 | * Called immediately before mounting occurs, and before `Component#render`.
700 | * Avoid introducing any side-effects or subscriptions in this method.
701 | *
702 | * This method will not stop working in React 17.
703 | *
704 | * Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps
705 | * prevents this from being invoked.
706 | *
707 | * @deprecated 16.3, use componentDidMount or the constructor instead
708 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
709 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
710 | */
711 | UNSAFE_componentWillMount?(): void;
712 | /**
713 | * Called when the component may be receiving new props.
714 | * React may call this even if props have not changed, so be sure to compare new and existing
715 | * props if you only want to handle changes.
716 | *
717 | * Calling `Component#setState` generally does not trigger this method.
718 | *
719 | * Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps
720 | * prevents this from being invoked.
721 | *
722 | * @deprecated 16.3, use static getDerivedStateFromProps instead; will stop working in React 17
723 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
724 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
725 | */
726 | componentWillReceiveProps?(nextProps: Readonly , nextContext: any): void;
727 | /**
728 | * Called when the component may be receiving new props.
729 | * React may call this even if props have not changed, so be sure to compare new and existing
730 | * props if you only want to handle changes.
731 | *
732 | * Calling `Component#setState` generally does not trigger this method.
733 | *
734 | * This method will not stop working in React 17.
735 | *
736 | * Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps
737 | * prevents this from being invoked.
738 | *
739 | * @deprecated 16.3, use static getDerivedStateFromProps instead
740 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
741 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
742 | */
743 | UNSAFE_componentWillReceiveProps?(nextProps: Readonly , nextContext: any): void;
744 | /**
745 | * Called immediately before rendering when new props or state is received. Not called for the initial render.
746 | *
747 | * Note: You cannot call `Component#setState` here.
748 | *
749 | * Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps
750 | * prevents this from being invoked.
751 | *
752 | * @deprecated 16.3, use getSnapshotBeforeUpdate instead; will stop working in React 17
753 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
754 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
755 | */
756 | componentWillUpdate?(nextProps: Readonly , nextState: Readonly , nextState: Readonly extends ComponentLifecycle {
775 | mixins?: Array extends Mixin {
790 | render(): ReactNode;
791 |
792 | [propertyName: string]: any;
793 | }
794 |
795 | function createRef extends NamedExoticComponent {
800 | defaultProps?: Partial | undefined;
801 | propTypes?: WeakValidationMap | undefined;
802 | }
803 |
804 | function forwardRef =
808 | // Pick would not be sufficient for this. We'd like to avoid unnecessary mapping and need a distributive conditional to support unions.
809 | // see: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
810 | // https://github.com/Microsoft/TypeScript/issues/28339
811 | P extends any ? ('ref' extends keyof P ? Pick > : P) : P;
812 | /** Ensures that the props do not include string ref, which cannot be forwarded */
813 | type PropsWithRef =
814 | // Just "P extends { ref?: infer R }" looks sufficient, but R will infer as {} if P is {}.
815 | 'ref' extends keyof P
816 | ? P extends { ref?: infer R | undefined }
817 | ? string extends R
818 | ? PropsWithoutRef & { ref?: Exclude = P & { children?: ReactNode | undefined };
824 |
825 | /**
826 | * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded,
827 | * or ComponentPropsWithoutRef when refs are not supported.
828 | */
829 | type ComponentProps & RefAttributes (
857 | Component: SFC, props: Readonly | S | null)) | (Pick | S | null),
487 | callback?: () => void
488 | ): void;
489 |
490 | forceUpdate(callback?: () => void): void;
491 | render(): ReactNode;
492 |
493 | // React.Props;
500 | /**
501 | * @deprecated
502 | * https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs
503 | */
504 | refs: {
505 | [key: string]: ReactInstance
506 | };
507 | }
508 |
509 | class PureComponent, nextContext: any): boolean;
631 | /**
632 | * Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as
633 | * cancelled network requests, or cleaning up any DOM elements created in `componentDidMount`.
634 | */
635 | componentWillUnmount?(): void;
636 | /**
637 | * Catches exceptions generated in descendant components. Unhandled exceptions will cause
638 | * the entire component tree to unmount.
639 | */
640 | componentDidCatch?(error: Error, errorInfo: ErrorInfo): void;
641 | }
642 |
643 | // Unfortunately, we have no way of declaring that the component constructor must implement this
644 | interface StaticLifecycle | null;
656 |
657 | type GetDerivedStateFromError | null;
665 |
666 | // This should be "infer SS" but can't use it yet
667 | interface NewLifecycle): SS | null;
677 | /**
678 | * Called immediately after updating occurs. Not called for the initial render.
679 | *
680 | * The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
681 | */
682 | componentDidUpdate?(prevProps: Readonly, snapshot?: SS): void;
683 | }
684 |
685 | interface DeprecatedLifecycle, nextContext: any): void;
757 | /**
758 | * Called immediately before rendering when new props or state is received. Not called for the initial render.
759 | *
760 | * Note: You cannot call `Component#setState` here.
761 | *
762 | * This method will not stop working in React 17.
763 | *
764 | * Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps
765 | * prevents this from being invoked.
766 | *
767 | * @deprecated 16.3, use getSnapshotBeforeUpdate instead
768 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
769 | * @see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
770 | */
771 | UNSAFE_componentWillUpdate?(nextProps: Readonly, nextContext: any): void;
772 | }
773 |
774 | interface Mixin