
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@wmik/use-file-input
Advanced tools
React based hooks for html file type inputs with drag and drop support.
npm install @wmik/use-file-input
function FileInputComponent() {
const LABEL_TEXT_DEFAULT = 'Click or drag/drop files to upload';
const LABEL_TEXT_HOVER = 'Drop files to upload';
const PLACEHOLDER_TEXT = 'No files';
let { fileInputRef, files, onFileInputChange } = useFileInput();
let hasFiles = Array.from(files?.values() ?? [])?.length > 0;
let styles = {
container: {
width: 400,
height: 400,
border: '1px dashed #dddccc'
},
label: {},
input: {
display: 'none'
},
list: {
display: hasFiles ? 'block' : 'none'
},
placeholder: {
display: !hasFiles ? 'block' : 'none'
}
};
return (
<main>
<div
style={styles.container}
onDragOver={onFileInputDragOver}
onDragStart={onFileInputDragStart}
onDragLeave={onFileInputDragLeave}
onDrop={onFileInputDrop}
>
<label
htmlFor="files"
style={styles.label}
children={isDraggingOver ? LABEL_TEXT_HOVER : LABEL_TEXT_DEFAULT}
/>
<input
multiple
id="files"
type="file"
name="files"
ref={fileInputRef}
style={styles.input}
onChange={onFileInputChange}
/>
</div>
<ul style={styles.list}>
{Array.from(files.values())?.map(file => (
<li key={file?.name}>
<span children={file?.name} />
<button
type="button"
aria-roledescription="delete"
onClick={() => files.delete(file)}
>
DELETE
</button>
</li>
))}
</ul>
<p style={styles.placeholder} children={PLACEHOLDER_TEXT} />
</main>
);
}
useFileInputCreates a custom file input object.
Parameters (FileInputProps)| Property | Type | Description |
|---|---|---|
| id | function | Custom ID generator |
| ref | object | Custom React reference object |
NOTE: * means it is required
Returns (FileInputHookObject)| Property | Type | Description |
|---|---|---|
| files | object | Map-like object for file cache I/O operations |
| {files}.get | function(key: string) | Method to get a file from the cache |
| {files}.set | function(file: File) | Method to add a file to the cache |
| {files}.delete | function(key: string) | Method to remove a file from the cache |
| {files}.has | function(key: string) | Method to check if an identifier exists in the cache |
| {files}.clear | function | Method to remove all files from the cache |
| {files}.keys | function | Method to list identifiers in the cache |
| {files}.values | function | Method to list files in the cache |
| {files}.entries | function | Method to list identifier-file pairs in the cache |
| fileInputRef | object | React referencing object for HTMLInputElement |
| isDraggingOver | boolean | Dragging state |
| onFileInputChange | function(event) | HTML change event handler |
| onFileInputDragStart | function(event) | HTML dragstart event handler |
| onFileInputDragLeave | function(event) | HTML dragleave event handler |
| onFileInputDragOver | function(event) | HTML dragover event handler |
| onFileInputDrop | function(event) | HTML drop event handler |
MIT ©2025
FAQs
React based hooks for html file type inputs
The npm package @wmik/use-file-input receives a total of 0 weekly downloads. As such, @wmik/use-file-input popularity was classified as not popular.
We found that @wmik/use-file-input demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.