React Barcode Component

1.6.1 · active · verified Sun Apr 19

react-barcode is a React component that streamlines the process of generating various barcode types within a React application. It acts as a wrapper around the robust JsBarcode library, abstracting away the direct DOM manipulation typically required for barcode rendering. The package is currently stable at version 1.6.1 and has seen active development, with recent minor releases adding support for more barcode formats like CODE128 (including GS1-128/EAN-128, CODE128A, B, and C) and minor type fixes. Its release cadence appears to be driven by feature additions and maintenance rather than strict time intervals. Key differentiators include its simple component-based API for React developers, comprehensive support for numerous barcode formats inherited from JsBarcode, and built-in TypeScript type definitions for enhanced developer experience.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to render a barcode using the `Barcode` component with configurable value and format.

import React, { FunctionComponent } from 'react';
import Barcode from 'react-barcode';

interface MyBarcodeGeneratorProps {
  dataValue: string;
  barcodeFormat?: string;
}

export const MyBarcodeGenerator: FunctionComponent<MyBarcodeGeneratorProps> = ({ dataValue, barcodeFormat = "CODE128" }) => {
    return (
        <div>
            <h1>Generated Barcode:</h1>
            <Barcode
                value={dataValue}
                format={barcodeFormat}
                width={2}
                height={100}
                displayValue={true}
                lineColor="#333333"
                background="#ffffff"
                margin={10}
            />
            <p>Scan this barcode!</p>
        </div>
    );
};

// Example usage:
// function App() {
//   return <MyBarcodeGenerator dataValue="YOUR_DATA_HERE" barcodeFormat="EAN13" />;
// }

view raw JSON →