How to print with QZ Tray in React Project with Zebra Printer to print product lables?

I’m working on a React ERP of products and goods, here in a component I have a print button which I want to print product barcode, labels, name and other details with Zebra printer, I have made connection in my MacOS system with Zebra printer and its successfully connected and working fine.

How can I use qz tray api to print my labels in ReactJS Project, I’ve made a component SmallLabelPrint.jsx where I designed how the label should look while print, but how to print that JSX component. Here is the code of label component:-

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>export default function SmallLabelPrint({data}) {
const labelHtml = `
<label style="width: 200px; height: 100px; border: 1px solid black;">
<p>${data.name}</p>
<p>${data.desc}</p>
</label>
`;
return <div dangerouslySetInnerHTML={{ __html: labelHtml }} />;
}
</code>
<code>export default function SmallLabelPrint({data}) { const labelHtml = ` <label style="width: 200px; height: 100px; border: 1px solid black;"> <p>${data.name}</p> <p>${data.desc}</p> </label> `; return <div dangerouslySetInnerHTML={{ __html: labelHtml }} />; } </code>
export default function SmallLabelPrint({data}) {
  const labelHtml = `
    <label style="width: 200px; height: 100px; border: 1px solid black;">
      <p>${data.name}</p>
      <p>${data.desc}</p>
    </label>
  `;

  return <div dangerouslySetInnerHTML={{ __html: labelHtml }} />;
}

Now in the below Product component I have a button to print with the details of the product. And with the documentation of the QZ Tray I have added this code, the connection is fine but its not printing and throwing this error:-

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>//AddSRF.jsx
const printWithQZTray = async () => {
try {
// Connect to QZ Tray websocket
await qz.websocket.connect();
// Find the desired printer
const printer = await qz.printers.find(printerName);
const formatData = <SmallLabelPrint data={printData} />;
const config = qz.configs.create(printerName, {
size: { width: 4, height: 6 }, // Adjust size as needed
});
// Prepare the print data (replace with your content)
const data = [
"nNn", // New label command
"q609n", // Label format selection
{
type: "raw",
flavor: "file", // Assuming text format
data: formatData, // Use the generated string as data
options: { language: "EPL" }, // Adjust language as needed
},
"nP1,1n", // Print command
];
// Send the print job
await qz.print(config, data);
} catch (error) {
console.error("Error printing:", error);
// Handle printing errors gracefully (e.g., display an error message to the user)
}
};
const handlePrint = async () => {
const formatData = <SmallLabelPrint data={printData} />;
await printWithQZTray(formatData);
};
//Jsx
<Button onClick={handlePrint}>Print</Button>
</code>
<code>//AddSRF.jsx const printWithQZTray = async () => { try { // Connect to QZ Tray websocket await qz.websocket.connect(); // Find the desired printer const printer = await qz.printers.find(printerName); const formatData = <SmallLabelPrint data={printData} />; const config = qz.configs.create(printerName, { size: { width: 4, height: 6 }, // Adjust size as needed }); // Prepare the print data (replace with your content) const data = [ "nNn", // New label command "q609n", // Label format selection { type: "raw", flavor: "file", // Assuming text format data: formatData, // Use the generated string as data options: { language: "EPL" }, // Adjust language as needed }, "nP1,1n", // Print command ]; // Send the print job await qz.print(config, data); } catch (error) { console.error("Error printing:", error); // Handle printing errors gracefully (e.g., display an error message to the user) } }; const handlePrint = async () => { const formatData = <SmallLabelPrint data={printData} />; await printWithQZTray(formatData); }; //Jsx <Button onClick={handlePrint}>Print</Button> </code>
//AddSRF.jsx

const printWithQZTray = async () => {
    try {
      // Connect to QZ Tray websocket
      await qz.websocket.connect();

      // Find the desired printer
      const printer = await qz.printers.find(printerName);
      const formatData = <SmallLabelPrint data={printData} />;
      const config = qz.configs.create(printerName, {
        size: { width: 4, height: 6 }, // Adjust size as needed
      });

      // Prepare the print data (replace with your content)
      const data = [
        "nNn", // New label command
        "q609n", // Label format selection
        {
            type: "raw",
            flavor: "file", // Assuming text format
            data: formatData, // Use the generated string as data
            options: { language: "EPL" }, // Adjust language as needed
        },
        "nP1,1n", // Print command
    ];

      // Send the print job
      await qz.print(config, data);

    } catch (error) {
      console.error("Error printing:", error);
      // Handle printing errors gracefully (e.g., display an error message to the user)
    }
  };

  const handlePrint = async () => {
    const formatData = <SmallLabelPrint data={printData} />;
    await printWithQZTray(formatData);
  };

//Jsx
<Button onClick={handlePrint}>Print</Button>

And with this getting this error:-
enter image description here

Maybe the code is wrong because I didn’t find anything where it is working with React project, kindly help with this, Thanks in advance.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật