Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
The fetch code in onNewScanResult is executed more than once once a QR code has been scanned, and also updating database. How to stop it from running?

executing the fetch code in onNewScanResult multiplt time and hence updating the database accordingly................

initialization of qr scanner.........

    this.html5QrcodeScanner = new Html5QrcodeScanner(
      qrcodeRegionId,
      config,
      verbose
    ); ```Executing scanner when qrcode is scanned```
    this.html5QrcodeScanner.render(
      this.props.qrCodeSuccessCallback,
      this.props.qrCodeErrorCallback
    );
  }
}

this is main qr code class........

class QrCode extends React.Component {
  constructor() {
    super();

    this.state = {
      decodedResults: [],
    };
    this.onNewScanResult = this.onNewScanResult.bind(this);
  }

this is where the executing multiple time is happing.......

    onNewScanResult(decodedText, decodedResult) {
    `geting data from loacal storage as we saved data earlier in the process about acess level`
    const qrRes = decodedText;
    const obj = JSON.parse(qrRes);
    const token = localStorage.getItem("user");
    const userData = JSON.parse(token);
    const username = userData[0].userId;
    const accesslevel = userData[0].accessLevel;
    const result = JSON.parse(qrRes);
    const ele = result.ele_name;
    const newdata = { ele, username, accesslevel };
    const data = {
      Element_detail: obj,
      accessLevel: newdata.accesslevel,
    };
    const verifyUser = localStorage.getItem("accessLeveldetails");
    const accessdetail = JSON.parse(verifyUser);
```checking is user is verified or not```......
    `checking the acess level you can ignore the checking focus on fetch part`....

    

This particular part is we have to stop executing multiple time so database is only entered with one value

      if (accessdetail.accessLevel === data.accessLevel) {
      try { ``` this fetch is updating database with multiple entries```
        fetch(
          data.accessLevel === 20
            ? `/v0/all_elements_image`
            : `/v0/${accessdetail.msg}`,
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify(obj),
          }
        ).then((res) => {
          console.log(res);
          if (!res) {
            throw res;
          }
          return res.json();
        });
      } catch (error) {
        console.log("Error:", error);
      }
    } else {
      alert("WRONG USER");
    }
  }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda