Socket
Socket
Sign inDemoInstall

react-code-scanner

Package Overview
Dependencies
9
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-code-scanner

A react component to scan bar codes and qr codes, it uses the zbar.wasm library in a web worker


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
1.78 MB
Created
Weekly downloads
 

Readme

Source

React Code Scanner

A react component to scan bar codes and qr codes, it uses the zbar.wasm library in a web worker.

This uses hooks, so needs React >= 16.8

## Install

npm i react-code-scanner

Usage

const [result, setResult] = useState('');
const [facingMode, setFacingMode] = useState('environment');

return (
  <div className="App">
    <h1>Code Scanner</h1>
    <div>Result: {result}</div>
    <div>
      <button onClick={() => setResult('')}>reset</button>
    </div>
    <div>
      <button
        onClick={() =>
          setFacingMode(facingMode === 'environment' ? 'user' : 'environment')
        }
      >
        current camera: {facingMode} switch camera
      </button>
    </div>
    <CodeScanner
      onResult={res => setResult(res.map(({ value }) => value).join(', '))}
      onError={setResult}
      facingMode={facingMode}
    />
  </div>
);

Props

namedefaultmeaning
width400the width in px of the camera view
height300the heigth in px of the camera view
onResultconsole.logthe callback that is invoked when a code is decoded
onErrorconsole.errorthe callback that is invoked when an error occours
maxVideoWidth640the width in px of the image taken from the camera and passed to the scanner
maxVideoHeight640the width in px of the image taken from the camera and passed to the scanner
facingMode'environment'this prop is used by devices with a back and a front camera and takes 2 values: 'environment' to use the back camera and 'user' to use the front camera
codeOverlayColor'#00ff00'the color of the code overlay that is dispalyed when a code is recognized
codeIndexColor'#ff0000'the color of the progressivo code id that is dispalyed when a code is recognized
mirrorUserImagetrueif true the component will mirror the image when using the front camera

FAQs

Last updated on 18 Sep 2020

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