Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

397
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda