Socket
Socket
Sign inDemoInstall

qrcode.react

Package Overview
Dependencies
7
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
Maintainers
1
Install size
204 kB
Created

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

[2.0.0] - 2022-03-05

Fixed

  • Switched to using unsafe_* lifecycle methods, eliminating a warning from non-production environments.

Removed

  • Removed support for React < 16.3.

Readme

Source

qrcode.react

A React component to generate QR codes.

Installation

npm install qrcode.react

Usage

var React = require('react');
var QRCode = require('qrcode.react');

React.render(
  <QRCode value="http://facebook.github.io/react/" />,
  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>.

LICENSE ISC

Keywords

FAQs

Last updated on 05 Mar 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