mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
style: optimize button code (#42005)
This commit is contained in:
parent
e1ff1a736f
commit
e5fad4c2d6
@ -120,13 +120,16 @@ const InternalButton: React.ForwardRefRenderFunction<
|
||||
const mergedDisabled = customDisabled ?? disabled;
|
||||
|
||||
const groupSize = React.useContext(GroupSizeContext);
|
||||
const loadingOrDelay: LoadingConfigType = React.useMemo(
|
||||
const loadingOrDelay = React.useMemo<LoadingConfigType>(
|
||||
() => getLoadingConfig(loading),
|
||||
[loading],
|
||||
);
|
||||
const [innerLoading, setLoading] = React.useState<Loading>(loadingOrDelay.loading);
|
||||
const [hasTwoCNChar, setHasTwoCNChar] = React.useState(false);
|
||||
const buttonRef = (ref as any) || React.createRef<HTMLAnchorElement | HTMLButtonElement>();
|
||||
|
||||
const internalRef = React.createRef<HTMLAnchorElement | HTMLButtonElement>();
|
||||
|
||||
const buttonRef = (ref as React.RefObject<any>) || internalRef;
|
||||
|
||||
const isNeedInserted = () =>
|
||||
React.Children.count(children) === 1 && !icon && !isUnBorderedButtonType(type);
|
||||
@ -147,10 +150,10 @@ const InternalButton: React.ForwardRefRenderFunction<
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
let delayTimer: number | null = null;
|
||||
let delayTimer: NodeJS.Timer | null = null;
|
||||
|
||||
if (loadingOrDelay.delay > 0) {
|
||||
delayTimer = window.setTimeout(() => {
|
||||
delayTimer = setTimeout(() => {
|
||||
delayTimer = null;
|
||||
setLoading(true);
|
||||
}, loadingOrDelay.delay);
|
||||
@ -160,7 +163,7 @@ const InternalButton: React.ForwardRefRenderFunction<
|
||||
|
||||
function cleanupTimer() {
|
||||
if (delayTimer) {
|
||||
window.clearTimeout(delayTimer);
|
||||
clearTimeout(delayTimer);
|
||||
delayTimer = null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user