npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-rfid-input-reader

v0.0.7

Published

A lightweight and flexible solution for integrating RFID readers into React applications. Designed to abstract the complexity of data capture, allowing you to attach reading logic to any existing input without compromising the UI/UX or visual structure of

Readme

React RFID Input Reader

A lightweight and flexible solution for integrating RFID readers into React applications. Designed to abstract the complexity of data capture, allowing you to attach reading logic to any existing input without compromising the UI/UX or visual structure of your project.

npm version license

📦 NPM: react-rfid-input-reader

🎬 Demo

RFID Scan Demo

✨ Features

  • 🎯 Easy to use - Ready-to-use hook with minimal configuration
  • 🔧 Highly configurable - Customize size limits and timeout
  • 📦 Lightweight - Zero external dependencies besides React
  • 🎨 Flexible - Works with any HTML input or custom component
  • 🔄 Auto-focus - Automatically keeps focus on input (configurable)
  • 🎁 Bonus modal - Optional modal component for visual feedback (completely decoupled from the core logic)

📦 Installation

npm install react-rfid-input-reader

or

yarn add react-rfid-input-reader

or

pnpm add react-rfid-input-reader

🚀 Basic Usage

Simple Input Example

import { useRFIDReader } from "react-rfid-input-reader";

function RFIDInput() {
  const { inputRef, handleKeyDown } = useRFIDReader({
    onRead: (code) => {
      console.log("RFID code read:", code);
    },
  });

  return (
    <input
      ref={inputRef}
      onKeyDown={handleKeyDown}
      placeholder="Tap your RFID card..."
      style={{ opacity: 0, position: "absolute" }}
    />
  );
}

Complete Example with Visual Feedback

import { useState } from "react";
import { useRFIDReader, RfIdValidateModal } from "react-rfid-input-reader";

function App() {
  const [isModalOpen, setIsModalOpen] = useState(false);
  const [status, setStatus] = useState<"loading" | "success" | "error">(
    "loading"
  );
  const [lastCode, setLastCode] = useState("");

  const { inputRef, handleKeyDown } = useRFIDReader({
    onRead: async (code) => {
      setLastCode(code);
      setIsModalOpen(true);
      setStatus("loading");

      // Simulate code validation
      const isValid = await validateRFIDCode(code);
      setStatus(isValid ? "success" : "error");
    },
    minLength: 8,
    maxLength: 12,
    timeoutDuration: 500,
    active: true,
  });

  return (
    <div>
      <input
        ref={inputRef}
        onKeyDown={handleKeyDown}
        placeholder="Waiting for scan..."
      />

      <RfIdValidateModal
        isOpen={isModalOpen}
        onClose={() => setIsModalOpen(false)}
        title="RFID Validation"
        message="Processing scan..."
        status={status}
      >
        {status === "success" && <p>Valid code: {lastCode}</p>}
        {status === "error" && <p>Invalid code!</p>}
      </RfIdValidateModal>
    </div>
  );
}

📖 API

useRFIDReader

Main hook for capturing RFID readings.

Parameters

| Property | Type | Default | Description | | ----------------- | ------------------------ | ------------ | ---------------------------------------------- | | onRead | (code: string) => void | required | Callback executed when a valid code is read | | minLength | number | 8 | Minimum code length to be considered valid | | maxLength | number | 12 | Maximum code length to be considered valid | | timeoutDuration | number | 500 | Time (ms) to clear the buffer after inactivity | | active | boolean | true | Enables/disables reading and auto-focus |

Return

| Property | Type | Description | | --------------- | ----------------------------- | ------------------------------------- | | inputRef | RefObject<HTMLInputElement> | Reference to attach to the input | | handleKeyDown | (e: KeyboardEvent) => void | Keyboard event handler | | focusInput | () => void | Function to force focus on the input | | clearBuffer | () => void | Function to manually clear the buffer |


RfIdValidateModal (Optional Bonus Component)

⚠️ Note: This modal is completely optional and decoupled from the core useRFIDReader hook. The hook works independently and you can use your own UI components for feedback. This modal is provided as a convenience bonus for quick prototyping or simple use cases.

Modal component for visual feedback during validation.

Props

| Property | Type | Default | Description | | ---------- | ----------------------------------- | ------------------------------- | -------------------------------- | | isOpen | boolean | required | Controls modal visibility | | onClose | () => void | required | Callback when closing the modal | | title | string | "RFID Validation" | Modal title | | message | string | "Waiting for card reading..." | Message displayed during loading | | status | 'loading' \| 'success' \| 'error' | "loading" | Visual state of the modal | | children | ReactNode | - | Custom content |

💡 How It Works

  1. The hook monitors keyboard events on the referenced input
  2. Typed characters are accumulated in an internal buffer
  3. When Enter is pressed, the code is validated by length
  4. If valid, the onRead callback is called with the code
  5. The buffer is automatically cleared after the configured timeout

🔧 Use Cases

  • Access control - Badge and card validation
  • Inventory - Reading RFID tags on products
  • Time tracking - Clock in/out registration
  • Events - Attendee check-in

📄 License

MIT © Kayo Silva