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

273
Views
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
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!