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:

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay