react-native-esc-pos-printer
Version:
An unofficial React Native library for printing on an EPSON TM printer with the Epson ePOS SDK for iOS and Epson ePOS SDK for Android
56 lines (55 loc) • 1.53 kB
JavaScript
;
import { useCallback, useEffect, useState } from 'react';
import { PrintersDiscovery } from "../PrintersDiscovery.js";
export function usePrintersDiscovery() {
const [printers, setPrinters] = useState([]);
const [isDiscovering, setIsDescovering] = useState(false);
const [printerError, setPrinterError] = useState(null);
useEffect(() => {
const removeListener = PrintersDiscovery.onDiscovery(deviceInfo => {
setPrinters(deviceInfo);
});
return () => {
removeListener();
};
}, []);
useEffect(() => {
const removeListener = PrintersDiscovery.onStatusChange(status => {
const isNextDiscovering = status === 'discovering';
if (isNextDiscovering) {
setPrinters([]);
setPrinterError(null);
}
setIsDescovering(isNextDiscovering);
});
return () => {
removeListener();
};
}, []);
useEffect(() => {
const removeListener = PrintersDiscovery.onError(error => {
setPrinterError(error);
});
return () => {
removeListener();
};
}, []);
const start = useCallback(params => {
PrintersDiscovery.start(params);
}, []);
const stop = useCallback(() => {
PrintersDiscovery.stop();
}, []);
const pairBluetoothDevice = useCallback(async macAddress => {
await PrintersDiscovery.pairBluetoothDevice(macAddress);
}, []);
return {
printers,
isDiscovering,
printerError,
start,
stop,
pairBluetoothDevice
};
}
//# sourceMappingURL=usePrintersDiscovery.js.map