-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
hoist-non-react-statics
implementation
- Loading branch information
1 parent
a1fc886
commit 1cd1385
Showing
1 changed file
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
// Copied directly from: | ||
// https://github.com/mridgway/hoist-non-react-statics/blob/main/src/index.js | ||
// https://unpkg.com/browse/@types/[email protected].1/index.d.ts | ||
// https://unpkg.com/browse/@types/[email protected].6/index.d.ts | ||
|
||
/** | ||
* Copyright 2015, Yahoo! Inc. | ||
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
*/ | ||
import type { | ||
ComponentType, | ||
ForwardRefExoticComponent, | ||
MemoExoticComponent, | ||
} from 'react' | ||
import type { ForwardRefExoticComponent, MemoExoticComponent } from 'react' | ||
import { ForwardRef, Memo, isMemo } from '../utils/react-is' | ||
|
||
const REACT_STATICS = { | ||
|
@@ -70,19 +66,19 @@ function getStatics(component: any) { | |
} | ||
|
||
export type NonReactStatics< | ||
S extends ComponentType<any>, | ||
Source, | ||
C extends { | ||
[key: string]: true | ||
} = {}, | ||
> = { | ||
[key in Exclude< | ||
keyof S, | ||
S extends MemoExoticComponent<any> | ||
keyof Source, | ||
Source extends MemoExoticComponent<any> | ||
? keyof typeof MEMO_STATICS | keyof C | ||
: S extends ForwardRefExoticComponent<any> | ||
: Source extends ForwardRefExoticComponent<any> | ||
? keyof typeof FORWARD_REF_STATICS | keyof C | ||
: keyof typeof REACT_STATICS | keyof typeof KNOWN_STATICS | keyof C | ||
>]: S[key] | ||
>]: Source[key] | ||
} | ||
|
||
const defineProperty = Object.defineProperty | ||
|
@@ -93,12 +89,15 @@ const getPrototypeOf = Object.getPrototypeOf | |
const objectPrototype = Object.prototype | ||
|
||
export default function hoistNonReactStatics< | ||
T extends ComponentType<any>, | ||
S extends ComponentType<any>, | ||
C extends { | ||
Target, | ||
Source, | ||
CustomStatic extends { | ||
[key: string]: true | ||
} = {}, | ||
>(targetComponent: T, sourceComponent: S): T & NonReactStatics<S, C> { | ||
>( | ||
targetComponent: Target, | ||
sourceComponent: Source, | ||
): Target & NonReactStatics<Source, CustomStatic> { | ||
if (typeof sourceComponent !== 'string') { | ||
// don't hoist over string (html) components | ||
|
||
|