fix(ImageUploader): wrap handleClearFile with useCallback

Prevents unnecessary re-renders by memoizing the callback, consistent
with handleFileChange which already uses useCallback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
雨霖铃
2026-05-27 13:52:11 +08:00
parent cdad9bda68
commit 2e2f6e9835
+2 -2
View File
@@ -41,7 +41,7 @@ const ImageUploader = ({
[onFileChange, onPreviewUrlChange], [onFileChange, onPreviewUrlChange],
); );
const handleClearFile = () => { const handleClearFile = useCallback(() => {
if (previewUrl) { if (previewUrl) {
URL.revokeObjectURL(previewUrl); URL.revokeObjectURL(previewUrl);
} }
@@ -50,7 +50,7 @@ const ImageUploader = ({
severity: 'success', severity: 'success',
autoHideDuration: 1000, autoHideDuration: 1000,
}); });
}; }, [previewUrl, onClearFile, showMessage, t]);
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files.length > 0) { if (e.target.files && e.target.files.length > 0) {