diff --git a/components/typography/Base/index.tsx b/components/typography/Base/index.tsx index 9c712fc529..56cef15b47 100644 --- a/components/typography/Base/index.tsx +++ b/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((props, ref) => { // ========================== Copyable ========================== const [enableCopy, copyConfig] = useMergedConfig(copyable); const [copied, setCopied] = React.useState(false); - const copyIdRef = React.useRef(); + const copyIdRef = React.useRef(null); const copyOptions: Pick = {}; if (copyConfig.format) { @@ -201,7 +201,9 @@ const Base = React.forwardRef((props, ref) => { } const cleanCopyId = () => { - window.clearTimeout(copyIdRef.current!); + if (copyIdRef.current) { + clearTimeout(copyIdRef.current); + } }; const onCopyClick = (e?: React.MouseEvent) => { @@ -214,7 +216,7 @@ const Base = React.forwardRef((props, ref) => { // Trigger tips update cleanCopyId(); - copyIdRef.current = window.setTimeout(() => { + copyIdRef.current = setTimeout(() => { setCopied(false); }, 3000);