0.2.0 • Published 4 years ago

@starrsoftware/barcodehandler v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

BarcodeHandler

Globally Handles paste events for barcodes and gives subscribed functions an object with the barcode and what type it conforms to

NPM JavaScript Style Guide

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