Match-id-3314488ef0f0a3913b65712abcdb657534438dc2

This commit is contained in:
* 2023-03-17 13:46:45 +08:00
parent 824b243b9e
commit 43602a11f2
2 changed files with 23 additions and 6 deletions

View File

@ -13,12 +13,20 @@
* See the Mulan PSL v2 for more details. * See the Mulan PSL v2 for more details.
*/ */
import { TYPE_FORWARD_REF } from '../../external/JSXElementType'; import {TYPE_FORWARD_REF, TYPE_MEMO} from '../../external/JSXElementType';
export function forwardRef(render: Function) { export function forwardRef(render: Function) {
return { const forwardRefJSXElement = {
vtype: TYPE_FORWARD_REF, $$typeof: TYPE_FORWARD_REF, // 规避三方件hoist-non-react-statics中通过$$typeof获取类型但获取不到导致render被覆盖
$$typeof: TYPE_FORWARD_REF, // 规避三方件hoist-non-react-statics中通过$$typeof获取类型但获取不到导致的错误
render, render,
}; };
// 控制vtype不能修改规避三方件hoist-non-react-statics修改vtype导致问题
Object.defineProperty(forwardRefJSXElement, 'vtype', {
configurable: false,
writable: false,
value: TYPE_FORWARD_REF,
});
return forwardRefJSXElement;
} }

View File

@ -16,9 +16,18 @@
import { TYPE_MEMO } from '../../external/JSXElementType'; import { TYPE_MEMO } from '../../external/JSXElementType';
export function memo<Props>(type, compare?: (oldProps: Props, newProps: Props) => boolean) { export function memo<Props>(type, compare?: (oldProps: Props, newProps: Props) => boolean) {
return { const memoJSXElement = {
vtype: TYPE_MEMO, $$typeof: TYPE_MEMO, // 规避三方件hoist-non-react-statics中通过$$typeof获取类型但获取不到导致type被覆盖
type: type, type: type,
compare: compare === undefined ? null : compare, compare: compare === undefined ? null : compare,
}; };
// 控制vtype不能修改规避三方件hoist-non-react-statics修改vtype导致问题
Object.defineProperty(memoJSXElement, 'vtype', {
configurable: false,
writable: false,
value: TYPE_MEMO,
});
return memoJSXElement;
} }