Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-qrcode-hook

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-qrcode-hook - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

14

index.js
const { useState, useEffect } = require("react");
const QrCode = require("qrcode");
const useQrCode = (code)=> {
const useQrCode = (...args) => {
const [qrCode, setQrCode] = useState(null);
useEffect(() => {
if (code) {
const canvas = document.createElement("canvas");
if (args.length && args[0]) {
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 1024;
QrCode.toDataURL(canvas, code).then(res => setQrCode(res));
QrCode.toDataURL(canvas, ...args).then(res => setQrCode(res));
}
}, [code]);
}, args);
return qrCode;
}
};
module.exports = useQrCode;
module.exports = useQrCode;
{
"name": "react-qrcode-hook",
"version": "1.0.0",
"version": "1.1.0",
"description": "React hook for creating QR Code data urls",

@@ -21,2 +21,3 @@ "main": "index.js",

"scripts": {
"test": "echo \"there are no tests and that... ok (for now)\"",
"example": "parcel example.html",

@@ -23,0 +24,0 @@ "contributors:add": "all-contributors add",

@@ -1,8 +0,8 @@

# `React QRCode Hook` 👾
# `React QRCode Hook` 📸
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)
> React hook for creating QR Code data urls
[![Edit useReact hook](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/6v25x8pyyn)
[![Edit useReact hook](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/xjojxm82jw)

@@ -24,3 +24,3 @@ ## Install

This hook returns a data URL which can be added as the source to an image. The
only parameter to the hook function is the string you want to codify.
only parameter to the hook function requires is the string you want to codify.

@@ -31,3 +31,3 @@ ```js

function App() {
useQrCode("Hello There");
const qrCode = useQrCode("Hello There");
return (

@@ -49,2 +49,54 @@ <div

This will produce a QR Code as follows.
<p align="center">
<img src="https://user-images.githubusercontent.com/29359616/53666334-dbcea200-3c3b-11e9-9565-96d30151bf43.png" width="86" />
</p>
## Advanced
You can also pass an `options` object as a second parameter to the hook as follows.
You can see a [complete list of options](https://www.npmjs.com/package/qrcode#qr-code-options) here.
```js
const qrCode = useQrCode(text, options);
```
And here is some sample code that uses `options`.
```js
const options = {
margin: 5,
scale: 10,
color: {
dark: '#ffffff',
light: '#000099',
},
};
function App() {
const qrCode = useQrCode('https://americanexpress.io', options);
return (
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<img alt="qr code" src={qrCode} />
</div>
);
}
```
The code above produces this QR Code. Notice how it changed the colors, size, and padding of the image?
<p align="center">
<img src="https://user-images.githubusercontent.com/29359616/53666074-23086300-3c3b-11e9-9c2d-8289219fe30e.png" width="350" />
</p>
## Example

@@ -73,4 +125,3 @@

<!-- prettier-ignore -->
| [<img src="https://avatars1.githubusercontent.com/u/6558157?v=4" width="100px;"/><br /><sub><b>Alex</b></sub>](https://ralexanderson.com)<br />[💻](https://github.com/alexanderson1993/react-qrcode-hook/commits?author=alexanderson1993 "Code") |
| :---: |
<table><tr><td align="center"><a href="https://ralexanderson.com"><img src="https://avatars1.githubusercontent.com/u/6558157?v=4" width="100px;" alt="Alex"/><br /><sub><b>Alex</b></sub></a><br /><a href="https://github.com/alexanderson1993/react-qrcode-hook/commits?author=alexanderson1993" title="Code">💻</a></td><td align="center"><a href="http://donavon.com"><img src="https://avatars3.githubusercontent.com/u/887639?v=4" width="100px;" alt="Donavon West"/><br /><sub><b>Donavon West</b></sub></a><br /><a href="https://github.com/alexanderson1993/react-qrcode-hook/commits?author=donavon" title="Code">💻</a> <a href="https://github.com/alexanderson1993/react-qrcode-hook/commits?author=donavon" title="Documentation">📖</a></td></tr></table>

@@ -77,0 +128,0 @@ <!-- ALL-CONTRIBUTORS-LIST:END -->

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc