import { useEffect, useRef } from "react"; import JsBarcode from "jsbarcode"; interface BarcodeDisplayProps { value: string; width?: number; height?: number; displayValue?: boolean; className?: string; } export default function BarcodeDisplay({ value, width = 2, height = 50, displayValue = true, className = "", }: BarcodeDisplayProps) { const canvasRef = useRef(null); useEffect(() => { if (canvasRef.current && value) { try { JsBarcode(canvasRef.current, value, { format: "CODE128", width, height, displayValue, fontSize: 14, margin: 10, }); } catch (error) { console.error("Error generating barcode:", error); } } }, [value, width, height, displayValue]); if (!value) { return (

尚未生成條碼

); } return ; }