
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
use-scan-detection
Advanced tools
A react hook for detecting barcode scanners in the DOM.
npm i use-scan-detection
useScanDetection({
onComplete: (code) => { console.log(code) }
});
Parameters are supplied by a config object:
| Parameter | Description |
|---|---|
| averageWaitTime | Average time between characters in milliseconds. Used to determine if input is from keyboard or a scanner. Defaults to 50. |
| timeToEvaluate | Time to evaluate the buffer after each character. |
| startCharacter | Optional. Character that barcode scanner prefixes input with. Buffer only starts if this character is read first. |
| endCharacter | Optional. Character that barcode scanner suffixes input with. Buffer is evaluated early if this character is read. Defaults to line return and escape. |
| onComplete | Function that is called when a complete barcode is scanned. Function is called with a single string which is the complete code. |
| onError | Optional. Function that is called when an incomplete barcode is scanned. Function is called with a single string which is the incomplete code. |
| minLength | Minimum number of characters for a barcode to successfully read. Should be greater than 0. Defaults to 1. |
| ignoreIfFocusOn | Optional. DOM element that if focused prevents codes from being read. |
| stopPropagation | Whether to call stopPropagation on each key event. Defaults to false. |
| preventDefault | Whether to call preventDefault on each key event. Defaults to false. |
| container | DOM element to listen for keydown events in. Defaults to document. |
This hook returns nothing.
import React, { useState } from 'react';
import useScanDetection from 'use-scan-detection';
const Input = () => {
const [value, setValue] = useState("");
useScanDetection({
onComplete: setValue,
minLength: 13 // EAN13
});
return (
<input
value={value}
type="text"
/>
);
};
export default Input
MIT Licensed
FAQs
A react hook for detecting barcode scanner input.
The npm package use-scan-detection receives a total of 1,713 weekly downloads. As such, use-scan-detection popularity was classified as popular.
We found that use-scan-detection demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.