mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 19:42:54 +08:00
chore: type optimization (#38460)
This commit is contained in:
parent
311a6e9f2f
commit
d292257e47
@ -9,9 +9,8 @@ export const getRenderPropValue = (
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRenderFunction = typeof propValue === 'function';
|
if (typeof propValue === 'function') {
|
||||||
if (isRenderFunction) {
|
return propValue();
|
||||||
return (propValue as RenderFunction)();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return propValue;
|
return propValue;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import useForceUpdate from './useForceUpdate';
|
import useForceUpdate from './useForceUpdate';
|
||||||
|
|
||||||
type UseSyncStateProps<T> = [() => T, (newValue: T) => void];
|
type UseSyncStateProps<T> = readonly [() => T, (newValue: T) => void];
|
||||||
|
|
||||||
export default function useSyncState<T>(initialValue: T): UseSyncStateProps<T> {
|
export default function useSyncState<T>(initialValue: T): UseSyncStateProps<T> {
|
||||||
const ref = React.useRef<T>(initialValue);
|
const ref = React.useRef<T>(initialValue);
|
||||||
@ -14,5 +14,5 @@ export default function useSyncState<T>(initialValue: T): UseSyncStateProps<T> {
|
|||||||
// re-render
|
// re-render
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
},
|
},
|
||||||
];
|
] as const;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ const ScrollNumber: React.FC<ScrollNumberProps> = ({
|
|||||||
className: classNames(`${prefixCls}-custom-component`, oriProps?.className, motionClassName),
|
className: classNames(`${prefixCls}-custom-component`, oriProps?.className, motionClassName),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return React.createElement(component as any, newProps, numberNodes);
|
return React.createElement(component, newProps, numberNodes);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ScrollNumber;
|
export default ScrollNumber;
|
||||||
|
@ -213,7 +213,7 @@ const Dropdown: DropdownInterface = props => {
|
|||||||
if (menu?.items) {
|
if (menu?.items) {
|
||||||
overlayNode = <Menu {...menu} />;
|
overlayNode = <Menu {...menu} />;
|
||||||
} else if (typeof overlay === 'function') {
|
} else if (typeof overlay === 'function') {
|
||||||
overlayNode = (overlay as OverlayFunc)();
|
overlayNode = overlay();
|
||||||
} else {
|
} else {
|
||||||
overlayNode = overlay;
|
overlayNode = overlay;
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ export default function useRemovePasswordTimeout(
|
|||||||
inputRef: React.RefObject<InputRef>,
|
inputRef: React.RefObject<InputRef>,
|
||||||
triggerOnMount?: boolean,
|
triggerOnMount?: boolean,
|
||||||
) {
|
) {
|
||||||
const removePasswordTimeoutRef = useRef<number[]>([]);
|
const removePasswordTimeoutRef = useRef<NodeJS.Timer[]>([]);
|
||||||
const removePasswordTimeout = () => {
|
const removePasswordTimeout = () => {
|
||||||
removePasswordTimeoutRef.current.push(
|
removePasswordTimeoutRef.current.push(
|
||||||
window.setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (
|
if (
|
||||||
inputRef.current?.input &&
|
inputRef.current?.input &&
|
||||||
inputRef.current?.input.getAttribute('type') === 'password' &&
|
inputRef.current?.input.getAttribute('type') === 'password' &&
|
||||||
@ -25,7 +25,12 @@ export default function useRemovePasswordTimeout(
|
|||||||
removePasswordTimeout();
|
removePasswordTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => removePasswordTimeoutRef.current.forEach(item => window.clearTimeout(item));
|
return () =>
|
||||||
|
removePasswordTimeoutRef.current.forEach(timer => {
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return removePasswordTimeout;
|
return removePasswordTimeout;
|
||||||
|
@ -28,7 +28,7 @@ const ElementsHolder = React.memo(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export default function useModal(): [Omit<ModalStaticFunctions, 'warn'>, React.ReactElement] {
|
export default function useModal(): [Omit<ModalStaticFunctions, 'warn'>, React.ReactElement] {
|
||||||
const holderRef = React.useRef<ElementsHolderRef>(null as any);
|
const holderRef = React.useRef<ElementsHolderRef>(null);
|
||||||
|
|
||||||
// ========================== Effect ==========================
|
// ========================== Effect ==========================
|
||||||
const [actionQueue, setActionQueue] = React.useState<(() => void)[]>([]);
|
const [actionQueue, setActionQueue] = React.useState<(() => void)[]>([]);
|
||||||
@ -52,14 +52,14 @@ export default function useModal(): [Omit<ModalStaticFunctions, 'warn'>, React.R
|
|||||||
|
|
||||||
const modalRef = React.createRef<HookModalRef>();
|
const modalRef = React.createRef<HookModalRef>();
|
||||||
|
|
||||||
let closeFunc: Function;
|
let closeFunc: Function | undefined;
|
||||||
const modal = (
|
const modal = (
|
||||||
<HookModal
|
<HookModal
|
||||||
key={`modal-${uuid}`}
|
key={`modal-${uuid}`}
|
||||||
config={withFunc(config)}
|
config={withFunc(config)}
|
||||||
ref={modalRef}
|
ref={modalRef}
|
||||||
afterClose={() => {
|
afterClose={() => {
|
||||||
closeFunc();
|
closeFunc?.();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -45,7 +45,7 @@ const Timeline: TimelineType = props => {
|
|||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
const timeLineItems = React.Children.toArray(children);
|
const timeLineItems = React.Children.toArray(children);
|
||||||
timeLineItems.push(pendingItem as any);
|
timeLineItems.push(pendingItem!);
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
timeLineItems.reverse();
|
timeLineItems.reverse();
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ import * as React from 'react';
|
|||||||
export default function useMergedConfig<Target>(
|
export default function useMergedConfig<Target>(
|
||||||
propConfig: any,
|
propConfig: any,
|
||||||
templateConfig?: Target,
|
templateConfig?: Target,
|
||||||
): [boolean, Target] {
|
): readonly [boolean, Target] {
|
||||||
return React.useMemo(() => {
|
return React.useMemo<readonly [boolean, Target]>(() => {
|
||||||
const support = !!propConfig;
|
const support = !!propConfig;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -13,6 +13,6 @@ export default function useMergedConfig<Target>(
|
|||||||
...templateConfig,
|
...templateConfig,
|
||||||
...(support && typeof propConfig === 'object' ? propConfig : null),
|
...(support && typeof propConfig === 'object' ? propConfig : null),
|
||||||
},
|
},
|
||||||
];
|
] as const;
|
||||||
}, [propConfig]);
|
}, [propConfig]);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
/** Similar with `useEffect` but only trigger after mounted */
|
/** Similar with `useEffect` but only trigger after mounted */
|
||||||
export default (callback: () => void, conditions: any[]) => {
|
const useUpdatedEffect = (callback: () => void, conditions?: React.DependencyList) => {
|
||||||
const mountRef = React.useRef(false);
|
const mountRef = React.useRef(false);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@ -12,3 +12,5 @@ export default (callback: () => void, conditions: any[]) => {
|
|||||||
}
|
}
|
||||||
}, conditions);
|
}, conditions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default useUpdatedEffect;
|
||||||
|
Loading…
Reference in New Issue
Block a user