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

274
Visualizações
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 à 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