npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-html5-qrcode-reader

v1.1.1

Published

A wrapper around html5-qrcode for react

Downloads

1,171

Readme

react-html5-qrcode-reader

npm version

A wrapper around html5-qrcode for react and SSR.

Check out the demo page for a live example. The source code of the example is available in the example folder (example/my-app).

The current version only includes two hooks that automates the process of including the html5-qrcode package, next versions will include wrapper components meant to simplify the process of acquiring a QR code scan from the html5-qrcode library.

Motivation

The motivation behind this package is based on the fact that the original html5-qrcode library offers react support but I had several difficulties including it in a next.js project.

Although the problem is mostly about including the library itself, using it as an NPM module did not work at all because the module is not ESM compatible.

This package serves as a solution for those who needs to use the html5-qrcode library in a react project but are unable to bundle a modular solution.

If you have any suggestion about cleverer / better ways to include the raw html5-qrcode library, please make a PR, the best I came up with is to inject in the head of the document the script pointing to the desired cdn.

If you want to see a working example, navigate to the example folder.

Available hooks

To see real world example usages of the hooks below, check the Example Usage section.

  • useAvailableDevices: returns the available devices to use for scanning.
  • useHtml5QrCode: returns the Html5Qrcode instance of the html 5 qr code library..
  • useHtml5QrCodeScanner: returns the Html5QrcodeScanner instance of the html 5 qr code library.

Example Usage

Like the html5-qrcode library package, you can either use the Html5QrcodeScanner or the Html5Qrcode approach.

Either way, use the desired hook, like the example below:

import { useHtml5QrCodeScanner } from 'react-html5-qrcode-reader';

function YourComponent() {
  const { Html5QrcodeScanner } = useHtml5QrCodeScanner(
    'url to the .min.js (see examples).'
  );

  useEffect(() => {
    if (Html5QrcodeScanner) {
      // Creates anew instance of `HtmlQrcodeScanner` and renders the block.
      let html5QrcodeScanner = new Html5QrcodeScanner(
        "reader",
        { fps: 10, qrbox: {width: 250, height: 250} },
        /* verbose= */ false);
      html5QrcodeScanner.render(
        (data: any) => console.log('success ->', data), 
        (err: any) => console.log('err ->', err)
      );
    }
  }, [Html5QrcodeScanner]);

  // beware: id must be the same as the first argument of Html5QrcodeScanner
  return (
    <div id='reader'></div>
  );
}

Testing

Please run the following to test the examples in the example folder if you clone the repository:

  • npm link react
  • npm link react-dom
  • Navigate to the example you want to test
  • cd node_modules/react && npm link
  • cd node_modules/react-dom && npm link