Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-use-file-upload

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-file-upload - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

15

dist/lib/useFileUpload.js

@@ -46,3 +46,3 @@ "use strict";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const setFiles = react_1.useCallback((e) => {
const setFiles = react_1.useCallback((e, mode = 'w') => {
var _a;

@@ -59,5 +59,12 @@ let filesArr = [];

}
setFilesState(filesArr);
handleSizes(filesArr);
}, []);
if (mode === 'w') {
setFilesState(filesArr);
handleSizes(filesArr);
}
else if (mode === 'a') {
const _files = [...files, ...filesArr];
setFilesState(_files);
handleSizes(_files);
}
}, [files]);
/** @function handleSizes */

@@ -64,0 +71,0 @@ const handleSizes = react_1.useCallback((files) => {

{
"name": "react-use-file-upload",
"version": "0.4.0",
"version": "0.4.1",
"description": "A React Hook to make dealing with file uploading easier.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -73,6 +73,6 @@ # React useFileUpload

A function that accepts the event emitted from the input field or drop zone, and creates an array of File objects.
A function that accepts the event emitted from the input field or drop zone, and creates an array of File objects. The default mode is set to, `w`, which means it will write over previous files each time new ones are attached. If you want previously attached files to not be deleted each time a user attaches new files, then you can opt in by calling setFiles like this, `setFiles(e, 'a')`, where the `a` stands for append. If you want the default behavior, there is no need to pass a second argument to this function.
```
(e: Event) => void
(e: Event, mode = 'w') => void
```

@@ -50,16 +50,25 @@ import { useState, useCallback, useEffect } from 'react';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const setFiles = useCallback((e: any): void => {
let filesArr: File[] = [];
const setFiles = useCallback(
(e: any, mode = 'w'): void => {
let filesArr: File[] = [];
if (e.currentTarget?.files) {
filesArr = Array.from(e.currentTarget.files);
} else if (e?.dataTransfer.files) {
filesArr = Array.from(e.dataTransfer.files);
} else {
console.error('Argument not recognized. Are you sure your passing setFiles an event object?');
}
if (e.currentTarget?.files) {
filesArr = Array.from(e.currentTarget.files);
} else if (e?.dataTransfer.files) {
filesArr = Array.from(e.dataTransfer.files);
} else {
console.error('Argument not recognized. Are you sure your passing setFiles an event object?');
}
setFilesState(filesArr);
handleSizes(filesArr);
}, []);
if (mode === 'w') {
setFilesState(filesArr);
handleSizes(filesArr);
} else if (mode === 'a') {
const _files = [...files, ...filesArr];
setFilesState(_files);
handleSizes(_files);
}
},
[files],
);

@@ -66,0 +75,0 @@ /** @function handleSizes */

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc