Socket
Socket
Sign inDemoInstall

qrcode.react

Package Overview
Dependencies
3
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    qrcode.react

React component to generate QR codes


Version published
Weekly downloads
1.5M
decreased by-0.87%
Maintainers
1
Install size
70.6 kB
Created
Weekly downloads
 

Package description

What is qrcode.react?

The qrcode.react npm package is a React component that uses the 'qrcode-generator' library to render QR codes as SVGs in React applications. It allows for easy creation and customization of QR codes directly within React components.

What are qrcode.react's main functionalities?

Generating a basic QR code

This feature allows you to generate a simple QR code by passing a string as the 'value' prop to the QRCode component.

{"import QRCode from 'qrcode.react';\n\nconst MyComponent = () => (\n  <QRCode value='http://facebook.github.io/react/' />\n);"}

Customizing the QR code

This feature enables customization of the QR code by setting props such as 'size' for dimension, 'bgColor' for background color, 'fgColor' for foreground color, and 'level' for error correction level.

{"import QRCode from 'qrcode.react';\n\nconst MyComponent = () => (\n  <QRCode\n    value='http://facebook.github.io/react/'\n    size={256}\n    bgColor={'#ffffff'}\n    fgColor={'#000000'}\n    level={'H'}\n  />\n);"}

Including a logo or image in the center of the QR code

This feature allows for the inclusion of a logo or image in the center of the QR code. The 'imageSettings' prop can be used to provide the image source and other related settings.

{"import QRCode from 'qrcode.react';\n\nconst MyComponent = () => (\n  <QRCode\n    value='http://facebook.github.io/react/'\n    size={256}\n    bgColor={'#ffffff'}\n    fgColor={'#000000'}\n    level={'H'}\n    includeMargin={true}\n    imageSettings={{\n      src: 'path/to/logo.png',\n      x: null,\n      y: null,\n      height: 24,\n      width: 24,\n      excavate: true,\n    }}\n  />\n);"}

Other packages similar to qrcode.react

Changelog

Source

[3.1.0] - 2022-06-25

Fixed

  • Made optional props optional, removing use of defaultProps. This may be a slight behavior change with TypeScript if previously passing null.
  • Fixed used of shapeRendering="crispEdges" in SVG component.

Readme

Source

qrcode.react

A React component to generate QR codes for rendering to the DOM.

Installation

npm install qrcode.react

Usage

qrcode.react exports three components, supporting rendering as SVG or Canvas. SVG is generally recommended as it is more flexible, but Canvas may be preferable.

All examples are shown using modern JavaScript modules and syntax. CommonJS require('qrcode.react') is also supported.

QRCodeSVG

import ReactDOM from 'react-dom';
import {QRCodeSVG} from 'qrcode.react';

ReactDOM.render(
  <QRCodeSVG value="https://reactjs.org/" />,
  document.getElementById('mountNode')
);

QRCodeCanvas

import ReactDOM from 'react-dom';
import {QRCodeCanvas} from 'qrcode.react';

ReactDOM.render(
  <QRCodeCanvas value="https://reactjs.org/" />,
  document.getElementById('mountNode')
);

QRCode - DEPRECATED

Note: Usage of this is deprecated as of v3. It is available as the default export for compatiblity with previous versions. The renderAs prop is only supported with this component.

import ReactDOM from 'react-dom';
import QRCode from 'qrcode.react';

ReactDOM.render(
  <QRCode value="https://reactjs.org/" renderAs="canvas" />,
  document.getElementById('mountNode')
);

Available Props

proptypedefault value
valuestring
renderAsstring ('canvas' 'svg')'canvas'
sizenumber128
bgColorstring (CSS color)"#FFFFFF"
fgColorstring (CSS color)"#000000"
levelstring ('L' 'M' 'Q' 'H')'L'
includeMarginbooleanfalse
imageSettingsobject (see below)

imageSettings

fieldtypedefault value
srcstring
xnumbernone, will center
ynumbernone, will center
heightnumber10% of size
widthnumber10% of size
excavatebooleanfalse

Custom Styles

qrcode.react will pass through any additional props to the underlying DOM node (<svg> or <canvas>). This allows the use of inline style or custom className to customize the rendering. One common use would be to support a responsive layout.

Note: In order to render QR Codes in <canvas> on high density displays, we scale the canvas element to contain an appropriate number of pixels and then use inline styles to scale back down. We will merge any additional styles, with custom height and width overriding our own values. This allows scaling to percentages but if scaling beyond the size, you will encounter blurry images. I recommend detecting resizes with something like react-measure to detect and pass the appropriate size when rendering to <canvas>.

Encoding Mode

qrcode.react supports encoding text only, in a single segment. The encoding library being used does minimal detection to determine if the text being encoded can follow an optimized path for Numeric or Alphanumeric modes, allowing for more data to be encoded. Otherwise, it will encode following Byte mode. This mode includes supports multi-byte Unicode characters such as Kanji, however it does not support the optimized Kanji encoding mode.

LICENSE

qrcode.react is licensed under the ISC license.

qrcode.react bundles QR Code Generator, which is available under the MIT license.

Keywords

FAQs

Last updated on 25 Jun 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc