New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@wmik/use-file-input

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wmik/use-file-input

React based hooks for html file type inputs

latest
Source
npmnpm
Version
1.0.0-alpha.1
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

use-file-input

React based hooks for html file type inputs with drag and drop support.

Features

  • 👀 Familiar API - Extends the Map API with minimal abstraction making it easy to use.
  • 🖱️ Drag n Drop - Supports HTML Drag and Drop API.
  • 🎛️ Configurable - Adjust settings to match your requirements.
  • 💅 Headless - Build your own custom user interface to fit your style.

Installation

npm install @wmik/use-file-input

Example

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>
  );
}

API

useFileInput

Creates a custom file input object.

Parameters (FileInputProps)

PropertyTypeDescription
idfunctionCustom ID generator
refobjectCustom React reference object

NOTE: * means it is required

Returns (FileInputHookObject)

PropertyTypeDescription
filesobjectMap-like object for file cache I/O operations
{files}.getfunction(key: string)Method to get a file from the cache
{files}.setfunction(file: File)Method to add a file to the cache
{files}.deletefunction(key: string)Method to remove a file from the cache
{files}.hasfunction(key: string)Method to check if an identifier exists in the cache
{files}.clearfunctionMethod to remove all files from the cache
{files}.keysfunctionMethod to list identifiers in the cache
{files}.valuesfunctionMethod to list files in the cache
{files}.entriesfunctionMethod to list identifier-file pairs in the cache
fileInputRefobjectReact referencing object for HTMLInputElement
isDraggingOverbooleanDragging state
onFileInputChangefunction(event)HTML change event handler
onFileInputDragStartfunction(event)HTML dragstart event handler
onFileInputDragLeavefunction(event)HTML dragleave event handler
onFileInputDragOverfunction(event)HTML dragover event handler
onFileInputDropfunction(event)HTML drop event handler

License

MIT ©2025

Keywords

react

FAQs

Package last updated on 15 Oct 2025

Did you know?

Socket

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.

Install

Related posts