Skip to content

Commit

Permalink
fix(Upload): fix manual uploadFilePercent not update display
Browse files Browse the repository at this point in the history
  • Loading branch information
Heising committed May 15, 2024
1 parent 348aa61 commit 43fa4c8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/upload/hooks/useUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function useUpload(props: TdUploadProps) {
const xhrReq = useRef<{ files: UploadFile[]; xhrReq: XMLHttpRequest }[]>([]);
const [toUploadFiles, setToUploadFiles] = useState<UploadFile[]>([]);
const [sizeOverLimitMessage, setSizeOverLimitMessage] = useState('');
const [update, forceUpdate] = useState({});

const locale = useMemo(() => merge({}, globalLocale, props.locale), [globalLocale, props.locale]);

Expand Down Expand Up @@ -59,7 +60,7 @@ export default function useUpload(props: TdUploadProps) {
isBatchUpload,
});
setDisplayFiles(files);
}, [props.multiple, toUploadFiles, uploadValue, autoUpload, isBatchUpload]);
}, [props.multiple, toUploadFiles, uploadValue, autoUpload, isBatchUpload, update]);

const uploadFilePercent = (params: { file: UploadFile; percent: number }) => {
const { file, percent } = params;
Expand All @@ -71,6 +72,11 @@ export default function useUpload(props: TdUploadProps) {
} else {
const index = uploadValue.findIndex((item) => file.raw === item.raw);
uploadValue[index] = { ...uploadValue[index], percent };
/**
* 使用强制更新,修复手动自定义上传的percent无效
* https://github.com/Tencent/tdesign-react/issues/2893
*/
forceUpdate({});
}
};

Expand Down

0 comments on commit 43fa4c8

Please sign in to comment.