Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

396
Views
Can I open a mobile device camera with React.js?

I need my QR code scanner to scan codes using a mobile device. At the moment the app works on a laptop/desktop webcam, but its intended purpose is to be used by a mobile device. From my own research, it looks like this is easy from React native, but I have no experience with react native. Is there some way I can achieve my goal with React JS? Or do I have to convert my React app somehow to React Native? I'm a beginner, so the simplest way possible would be great. Here's my QR code scanner component

import React, { useState } from "react";
import { Fab, TextareaAutosize } from "@material-ui/core";
import { ArrowBack } from "@material-ui/icons";
import { Link } from "react-router-dom";
import QrScan from "react-qr-reader";
import { useToolProvider } from "../contexts/tool";

const QRscanner = () => {
  const [qrscan, setQrscan] = useState("no result");
  const { state, updateInventory } = useToolProvider();

  const handleError = (err) => {
    console.error(err);
  };
  const [scanResults, setScanResults] = useState();
  const [scanTrigger, setScanTrigger] = useState(false);
  const qrScanTrigger = () => {
    setScanTrigger(true);
  };
  const handleScan = (data) => {
    if (data) {
      setScanResults(data);
    }
  };
  const submit = () => {
    updateInventory(scanResults);
  };

  return (
    <div>
      <Link to="/">
        <Fab style={{ marginRight: 10 }} color="primary">
          <ArrowBack />
        </Fab>
      </Link>
      <span>QR Scanner</span>

      <center>
        <div style={{ marginTop: 30 }}>
          <QrScan
            delay={300}
            onError={handleError}
            onScan={handleScan}
            style={{ height: 240, width: 320 }}
            reactivateTimeout={500}
            onEvent={qrScanTrigger}
          />
        </div>
      </center>

      <TextareaAutosize
        style={{ fontSize: 18, width: 320, height: 100, marginTop: 100 }}
        rowsMax={4}
        defaultValue={qrscan}
        value={qrscan}
      />
      <div>
        <h3>{scanResults}</h3>

        {scanTrigger && <h1>it worked</h1>}
        <button onClick={submit}>Submit</button>
        <p>{JSON.stringify(state)}</p>
      </div>
    </div>
  );
};

export default QRscanner;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!