File size: 1,000 Bytes
93dd66e
2d611fd
f3a9ef2
26c4b30
 
 
 
f80b091
 
 
 
26c4b30
 
 
 
 
 
 
 
 
 
 
 
38448fc
26c4b30
 
 
 
 
 
f80b091
 
f3a9ef2
f80b091
f3a9ef2
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { DropzoneOptions, useDropzone } from 'react-dropzone';
// import { toast } from 'react-hot-toast';

const useImageUpload = (
  options?: Partial<DropzoneOptions>,
  onDrop?: (files: File[]) => void,
) => {
  const { getRootProps, getInputProps, isDragActive } = useDropzone({
    accept: {
      'image/*': ['.jpeg', '.png'],
    },
    multiple: false,
    onDrop: onDrop
      ? onDrop
      : acceptedFiles => {
          // if (acceptedFiles.length > 10) {
          // 	toast('You can only upload 10 images max.', {
          // 		icon: '⚠️',
          // 	});
          // }
          acceptedFiles.forEach(file => {
            try {
              const reader = new FileReader();
              reader.onloadend = () => {};
              reader.readAsDataURL(file);
            } catch (err) {
              console.error(err);
            }
          });
        },
    ...options,
  });

  return { getRootProps, getInputProps, isDragActive };
};

export default useImageUpload;