Skip to content

Latest commit

 

History

History
51 lines (43 loc) · 1.23 KB

File metadata and controls

51 lines (43 loc) · 1.23 KB

API

  1. discovery
  2. Printer

Example

  import { usePrintersDiscovery, Printer } from 'react-native-esc-pos-printer';

  ...

  const { start, isDiscovering, printers } =
    usePrintersDiscovery();

  const print = () => {
    printersData.forEach(printersData => {
        const printerInstance = new Printer({
          target: printersData.target,
          deviceName: printersData.deviceName,
        });

        const res = await printerInstance.addQueueTask(async () => {
          await Printer.tryToConnectUntil(
            printerInstance,
            (status) => status.online.statusCode === PrinterConstants.TRUE
          );
          await printerInstance.addText('DUDE!');
          await printerInstance.addFeedLine();
          await printerInstance.addCut();
          const result = await printerInstance.sendData();
          await printerInstance.disconnect();
          return result;
      })
    })
  }

  return (
    ...
        <Button
          loading={isDiscovering}
          title="Search"
          onPress={() => start()}
        />
       {printers.length ? <Button
          title="Print"
          onPress={() => print()}
        /> : null}
    ...
  );