Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
react-hook-qrcode-svg
Advanced tools
React hook that generates QR code and returns SVG path.
You can use SVG path for <svg>
element rendering or building SVG data URL (useful when it comes to downloading or printing).
See QR code generator: QR-Code-generator.
yarn add react-hook-qrcode-svg
or
npm install react-hook-qrcode-svg
import React from 'react'
import useQRCodeGenerator from 'react-hook-qrcode-svg'
const QRCODE_SIZE = 256
const QRCODE_LEVEL = 'Q'
const QRCODE_BORDER = 4
const QRCodeComponent = ({ value }) => {
const { path, viewBox } = useQRCodeGenerator(value, QRCODE_LEVEL, QRCODE_BORDER)
return (
<svg
width={QRCODE_SIZE}
height={QRCODE_SIZE}
viewBox={viewBox}
stroke='none'
>
<rect width='100%' height='100%' fill='#ffffff' />
<path d={path} fill='#000000' />
</svg>
)
}
import React, { useMemo } from 'react'
import useQRCodeGenerator from 'react-hook-qrcode-svg'
const LOGO_PATH = `M 53.00,0.44
C 74.13,-2.27 95.87,3.14 110.83,19.04
139.01,48.98 132.42,101.51 95.00,120.74
81.22,127.82 73.98,128.17 59.00,128.00
31.12,127.67 7.43,105.37 1.24,79.00
-0.37,72.18 -0.01,67.86 0.00,61.00
0.05,29.96 23.24,6.01 53.00,0.44 Z
`
const LOGO_SIZE = 128
const QRCODE_SIZE = 256
const QRCODE_LEVEL = 'Q'
const QRCODE_BORDER = 4
const QRCodeComponent = ({ value }) => {
// Generate SVG path
const { path, viewBox, excludePoints } = useQRCodeGenerator(
value,
QRCODE_LEVEL,
QRCODE_BORDER,
// Exclude rectangular area from QR Code
{
width: 42,
height: 42,
baseSize: QRCODE_SIZE
}
)
// Calculate logo path transformations
const [scaleX, scaleY, translateX, translateY] = useMemo(() => {
const scaleX = (excludePoints.x2 - excludePoints.x1) / LOGO_SIZE
const scaleY = (excludePoints.y2 - excludePoints.y1) / LOGO_SIZE
const translateX = excludePoints.x1 + QRCODE_BORDER
const translateY = excludePoints.y1 + QRCODE_BORDER
return [scaleX, scaleY, translateX, translateY]
}, [excludePoints])
// Render SVG element
return (
<svg
width={QRCODE_SIZE}
height={QRCODE_SIZE}
viewBox={viewBox}
stroke='none'
>
<rect width='100%' height='100%' fill='#ffffff' />
<path d={path} fill='#000000' />
<g transform={`translate(${translateX}, ${translateY})`}>
<g transform={`scale(${scaleX}, ${scaleY})`}>
<path
fill='#cccccc'
d={LOGO_PATH}
shapeRendering='geometricPrecision'
/>
</g>
</g>
</svg>
)
}
text: string,
level: 'L' | 'M' | 'Q' | 'H',
border: number = 0,
exclude: {
x?: number
y?: number
width: number
height: number
baseSize: number
} | null = null
FAQs
React hook for QR code generation as SVG path
The npm package react-hook-qrcode-svg receives a total of 393 weekly downloads. As such, react-hook-qrcode-svg popularity was classified as not popular.
We found that react-hook-qrcode-svg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.