You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-use-barcode

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-barcode

React Hook to generate barcode image used in any platform

1.0.4
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

react-use-barcode

A React hook for generating barcode images.

Installation

npm install react-use-barcode

Usage

To use the useBarcode hook, simply import it into your component and call it with the value and options parameters:

import { useBarcode, BarcodeOptions } from 'react-use-barcode';

const MyComponent = () => {
  const options: BarcodeOptions = { height: 50, width: 3 };
  const barcode = useBarcode('123456789', options);

  return (
    <img src={barcode} alt="Barcode" />
  );
};

The useBarcode hook takes two parameters:

value: the value to be encoded as a barcode (required).

options: an object containing options for the barcode generation (optional) The options parameter is an object with properties:

  • height: the height of the barcode image.
  • width: the width of the barcode image.
  • Any option passed to JSBarcode

The useBarcode hook returns a base64-encoded string representing the barcode image, or undefined if the image has not yet been generated.

Example

Here's an example of how to use the useBarcode hook in a component:

import { useBarcode, BarcodeOptions } from 'react-use-barcode';

const MyComponent = () => {
  const options: BarcodeOptions = { height: 50, width: 3 };
  const barcode = useBarcode('123456789', options);

  return (
    <img src={barcode} alt="Barcode" />
  );
};

Keywords

React barcode

FAQs

Package last updated on 09 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts