@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
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/barcodehandlerExample 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>
);
}