Skip to content

Commit 39b1ef4

Browse files
authored
[Update use-upload-files.tsx] [Bug fix] Added an 'id' field in files[] (#158)
Added an 'id' field in files array (to be used as 'key' in react). This field should be used as 'key'
1 parent 177a2e8 commit 39b1ef4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/next-s3-upload/src/hooks/use-upload-files.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import { FileInput } from '../components/file-input';
33
import { useRef, useState } from 'react';
4+
import { uuid } from '../utils/keys';
45

56
type TrackedFile = {
67
file: File;
78
progress: number;
89
uploaded: number;
910
size: number;
11+
id: string;
1012
};
1113

1214
export const useUploadFiles = () => {
@@ -31,6 +33,7 @@ export const useUploadFiles = () => {
3133
? {
3234
file,
3335
uploaded,
36+
id: trackedFile.id,
3437
size: file.size,
3538
progress: file.size ? (uploaded / file.size) * 100 : 0,
3639
}
@@ -42,7 +45,7 @@ export const useUploadFiles = () => {
4245
let addFile = (file: File) => {
4346
setFiles(files => [
4447
...files,
45-
{ file, progress: 0, uploaded: 0, size: file.size },
48+
{ file, progress: 0, uploaded: 0, size: file.size, id: uuid()},
4649
]);
4750
};
4851

0 commit comments

Comments
 (0)