Hello I want to print a receipt with Bluetooth thermal printer in react native. I have code as of now its working but giving a warning. with this code may i able to print a receipt please help to get rid of this warning also. here is my code. Warning possible Unhandled Promise Rejection (id: 0) TypeError:null is not an object (evaluating 'RNBLEPrinter.init')
import React, { useState, useEffect } from "react";
import {
USBPrinter,
NetPrinter,
BLEPrinter,
} from "react-native-thermal-receipt-printer";
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
function Print() {
const [printers, setPrinters] = useState([]);
const [currentPrinter, setCurrentPrinter] = useState();
useEffect(() => {
BLEPrinter.init().then(() => {
BLEPrinter.getDeviceList().then(setPrinters);
});
}, []);
(_connectPrinter) => (printer) => {
//connect printer
BLEPrinter.connectPrinter(printer.inner_mac_address).then(
setCurrentPrinter,
(error) => console.warn(error)
);
};
printTextTest = () => {
currentPrinter && USBPrinter.printText("this is new print");
};
printBillTest = () => {
currentPrinter && USBPrinter.printBill("this is for bill testing");
};
return (
<View style={styles.container}>
{printers.map((printer) => (
<TouchableOpacity
key={printer.inner_mac_address}
onPress={() => _connectPrinter(printer)}
>
{`device_name: ${printer.device_name}, inner_mac_address: ${printer.inner_mac_address}`}
</TouchableOpacity>
))}
<TouchableOpacity onPress={printTextTest}>
<Text>Print Text</Text>
</TouchableOpacity>
<TouchableOpacity onPress={printBillTest}>
<Text>Print Bill Text</Text>
</TouchableOpacity>
</View>
);
}
export default Print;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
});
That looks like it may be coming from the react-native-thermal-receipt-printer library. Id look in the node module usually in the index.js file it will make that init call.