Skip to content

Commit

Permalink
fix: import useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
veloii committed Oct 23, 2024
1 parent 7d38176 commit c18d02c
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions packages/react/src/components/primitive/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createContext,
useCallback,
useContext,
useMemo,
useRef,
useState,
} from "react";
Expand Down Expand Up @@ -260,47 +261,50 @@ export function Root<
if (mode === "auto") void uploadFiles(filesToUpload);
});

const primitiveValues = useMemo<PrimitiveContextValues>(() => ({
files,
setFiles: (files) => {
setFiles(files);
props.onChange?.(files);
const primitiveValues = useMemo<PrimitiveContextValues>(
() => ({
files,
setFiles: (files) => {
setFiles(files);
props.onChange?.(files);

if (files.length <= 0) {
if (fileInputRef.current) fileInputRef.current.value = "";
return;
}
if (mode === "manual") return;
if (files.length <= 0) {
if (fileInputRef.current) fileInputRef.current.value = "";
return;
}
if (mode === "manual") return;

void uploadFiles(files);
},
uploadFiles: () => void uploadFiles(files),
abortUpload: () => {
acRef.current.abort();
acRef.current = new AbortController();
},
uploadProgress,
state,
accept,
fileTypes,
options: { mode, multiple },
refs: {
focusElementRef,
fileInputRef,
},
routeConfig,
}), [
files,
setFiles,
uploadFiles,
uploadProgress,
state,
accept,
fileTypes,
mode,
multiple,
routeConfig,
]);
void uploadFiles(files);
},
uploadFiles: () => void uploadFiles(files),
abortUpload: () => {
acRef.current.abort();
acRef.current = new AbortController();
},
uploadProgress,
state,
accept,
fileTypes,
options: { mode, multiple },
refs: {
focusElementRef,
fileInputRef,
},
routeConfig,
}),
[
files,
setFiles,
uploadFiles,
uploadProgress,
state,
accept,
fileTypes,
mode,
multiple,
routeConfig,
],
);

return (
<PrimitiveContext.Provider value={primitiveValues}>
Expand Down

0 comments on commit c18d02c

Please sign in to comment.