apenab / react-dymo

Collections of react utilities to handle the Dymo LabelWriter web service
27 stars 10 forks source link
dymo dymo-label dymo-labelwriter dymo-printer dymo-service hacktoberfest hook hooks javascript label react react-hooks reactjs

react-dymo

Collections of javascript and react utilities to handle the Dymo LabelWriter web service.

NPM JavaScript Style Guide

Install

npm install --save react-dymo-hooks

or

yarn add react-dymo-hooks

API

printLabel()

Print Dymo labels

Arguments

useDymoCheckService()

Return the status of DYMO Label Web Service

Arguments

Returns

useDymoFetchPrinters()

Returns the available DYMO Labelwriter Printer

Arguments

Returns

Object containing:

useDymoOpenLabel()

Render Label

Arguments

Returns

Object containing:

Run examples

Inside the root directory project

  1. Switch to the directory example/
  2. yarn install or npm install
  3. yarn run start or npm run-script start

Examples

Print a Dymo Label

import {printLabel} from "react-dymo-hooks";

async function handlePrintSingleLabel(printerName, labelXml) {
  try {
    const response = await printLabel(printerName, labelXml);
    console.info(response);
  } catch (error) {
    console.error(error);
  }
}

<button onClick={() => handlePrintLabel(printer, xml)} />;
import {useDymoOpenLabel, useDymoCheckService} from "react-dymo-hooks";

const DymoLabelPreview = () => {
  const statusDymoService = useDymoCheckService();
  const {label, statusOpenLabel, errorOpenLabel} = useDymoOpenLabel(statusDymoService, xmlFile);

  if (label) {
    return <img src={"data:image/png;base64," + label} alt="dymo label preview" />;
  } else {
    return null;
  }
};

License

MIT © apenab