DEV Community

Cover image for The easiest way to generate Barcode with react-barcode
Create Next App
Create Next App

Posted on • Edited on

10 2

The easiest way to generate Barcode with react-barcode

react-barcode

Overview

react-barcode component is a light-weight and high-performance component that displays industry-standard 1D and 2D barcodes for React app. Generated barcodes are optimized for printing and on-screen scanning. It is designed for ease of use and does not require fonts.

Live demo

Customization

react-barcode component is easily customizable. It provides options to customize its color, height, width, and more.

Label

react-barcode provides an option to display a barcode with or without text along with alignment options for React.

Type

react-barcode supports wide a range of types.

Features

  • Compatible with both JavaScript and TypeScript
  • Generate as SVG, Canvas and Image
  • Support multiple barcodes type

Installation

react-barcode is available on npm. It can be installed with the following command:



npm install --save @createnextapp/react-barcode


Enter fullscreen mode Exit fullscreen mode

react-barcode is available on yarn as well. It can be installed with the following command:



yarn add @createnextapp/react-barcode


Enter fullscreen mode Exit fullscreen mode

Usage

SVG



import React from 'react';
import { useBarcode } from '@createnextapp/react-barcode';

function App() {
  const { inputRef } = useBarcode({
    value: 'createnextapp',
    options: {
      background: '#ccffff',
    }
  });

  return <svg ref={inputRef} />;
};

export default App;


Enter fullscreen mode Exit fullscreen mode

react-barcode svg

Canvas



import React from 'react';
import { useBarcode } from '@createnextapp/react-barcode';

function App() {
  const { inputRef } = useBarcode({
    value: 'createnextapp',
    options: {
      displayValue: false,
      background: '#ffc0cb',
    }
  });

  return <canvas ref={inputRef} />;
};

export default App;


Enter fullscreen mode Exit fullscreen mode

react-barcode canvas

Image



import React from 'react';
import { useBarcode } from '@createnextapp/react-barcode';

function App() {
  const { inputRef } = useBarcode({
    value: 'createnextapp',
    options: {
      background: '#ffff00',
    }
  });

  return <img ref={inputRef} />;
};

export default App;


Enter fullscreen mode Exit fullscreen mode

react-barcode image

To learn more how to use react-barcode:

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay