Browse Source

type: optimization copyIdRef type (#43257)

pull/43269/head
thinkasany 1 year ago
committed by GitHub
parent
commit
90a381df2a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      components/typography/Base/index.tsx

16
components/typography/Base/index.tsx

@ -11,17 +11,17 @@ import useMergedState from 'rc-util/lib/hooks/useMergedState';
import omit from 'rc-util/lib/omit';
import { composeRef } from 'rc-util/lib/ref';
import * as React from 'react';
import { isStyleSupport } from '../../_util/styleChecker';
import TransButton from '../../_util/transButton';
import { ConfigContext } from '../../config-provider';
import useLocale from '../../locale/useLocale';
import type { TooltipProps } from '../../tooltip';
import Tooltip from '../../tooltip';
import { isStyleSupport } from '../../_util/styleChecker';
import TransButton from '../../_util/transButton';
import Editable from '../Editable';
import useMergedConfig from '../hooks/useMergedConfig';
import useUpdatedEffect from '../hooks/useUpdatedEffect';
import type { TypographyProps } from '../Typography';
import Typography from '../Typography';
import useMergedConfig from '../hooks/useMergedConfig';
import useUpdatedEffect from '../hooks/useUpdatedEffect';
import Ellipsis from './Ellipsis';
import EllipsisTooltip from './EllipsisTooltip';
@ -193,7 +193,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
// ========================== Copyable ==========================
const [enableCopy, copyConfig] = useMergedConfig<CopyConfig>(copyable);
const [copied, setCopied] = React.useState(false);
const copyIdRef = React.useRef<number>();
const copyIdRef = React.useRef<NodeJS.Timeout | null>(null);
const copyOptions: Pick<CopyConfig, 'format'> = {};
if (copyConfig.format) {
@ -201,7 +201,9 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
}
const cleanCopyId = () => {
window.clearTimeout(copyIdRef.current!);
if (copyIdRef.current) {
clearTimeout(copyIdRef.current);
}
};
const onCopyClick = (e?: React.MouseEvent<HTMLDivElement>) => {
@ -214,7 +216,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
// Trigger tips update
cleanCopyId();
copyIdRef.current = window.setTimeout(() => {
copyIdRef.current = setTimeout(() => {
setCopied(false);
}, 3000);

Loading…
Cancel
Save