@starrsoftware/barcodehandler
v0.2.0
Published
Globally Handles paste events for barcodes and gives subscribed functions an object with the barcode and what type it conforms to
Downloads
4
Readme
BarcodeHandler
Globally Handles paste events for barcodes and gives subscribed functions an object with the barcode and what type it conforms to
Install
npm install --save @starrsoftware/barcodehandler
Example Usage
import React, { useState } from 'react';
import BarcodeHandler, { AddListener } from '@starrsoftware/barcodehandler';
export default function BarcodeHandlerExample(props) {
const [barcode, setBarcode] = useState({});
useEffect(() => {
AddListener('HomePage', onScan);
});
const onScan = (value, type, typeName) => {
//Do some stuff with your barcode
console.log(`${typeName}:${value}`);
setBarcode({ value, type, typeName });
};
return (
<React.Fragment>
<BarcodeHandler />
<div>Barcode Type: {barcode.typeName}</div>
<div>Barcode Value: {barcode.name}</div>
</React.Fragment>
);
}