Browse Source

type: optimization React.useRef type (#38388)

pull/38393/head
lijianan 2 years ago
committed by GitHub
parent
commit
038c9d0763
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      components/_util/ActionButton.tsx
  2. 2
      components/back-top/index.tsx
  3. 4
      components/upload/Upload.tsx
  4. 7
      components/upload/UploadList/ListItem.tsx

9
components/_util/ActionButton.tsx

@ -22,7 +22,7 @@ function isThenable(thing?: PromiseLike<any>): boolean {
const ActionButton: React.FC<ActionButtonProps> = props => {
const clickedRef = React.useRef<boolean>(false);
const ref = React.useRef<any>();
const ref = React.useRef<HTMLInputElement>(null);
const [loading, setLoading] = useState<ButtonProps['loading']>(false);
const { close } = props;
const onInternalClose = (...args: any[]) => {
@ -30,10 +30,11 @@ const ActionButton: React.FC<ActionButtonProps> = props => {
};
React.useEffect(() => {
let timeoutId: any;
let timeoutId: NodeJS.Timer | null = null;
if (props.autoFocus) {
const $this = ref.current as HTMLInputElement;
timeoutId = setTimeout(() => $this.focus());
timeoutId = setTimeout(() => {
ref.current?.focus();
});
}
return () => {
if (timeoutId) {

2
components/back-top/index.tsx

@ -56,7 +56,7 @@ const BackTop: React.FC<BackTopProps> = props => {
});
const ref = React.createRef<HTMLDivElement>();
const scrollEvent = React.useRef<any>();
const scrollEvent = React.useRef<ReturnType<typeof addEventListener>>(null);
const getDefaultTarget = () =>
ref.current && ref.current.ownerDocument ? ref.current.ownerDocument : window;

4
components/upload/Upload.tsx

@ -60,7 +60,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
const [dragState, setDragState] = React.useState<string>('drop');
const upload = React.useRef<any>();
const upload = React.useRef<RcUpload>(null);
warning(
'fileList' in props || !('value' in props),
@ -276,7 +276,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
item.status = 'removed';
}
});
upload.current?.abort(currentFile);
upload.current?.abort(currentFile as RcFile);
onInternalChange(currentFile, removedFileList);
}

7
components/upload/UploadList/ListItem.tsx

@ -82,14 +82,15 @@ const ListItem = React.forwardRef(
// Delay to show the progress bar
const [showProgress, setShowProgress] = React.useState(false);
const progressRafRef = React.useRef<any>();
const progressRafRef = React.useRef<NodeJS.Timer | null>(null);
React.useEffect(() => {
progressRafRef.current = setTimeout(() => {
setShowProgress(true);
}, 300);
return () => {
window.clearTimeout(progressRafRef.current);
if (progressRafRef.current) {
clearTimeout(progressRafRef.current);
}
};
}, []);

Loading…
Cancel
Save