Skip to content

Commit

Permalink
Merge pull request #196 from getAlby/task-qr-scanner
Browse files Browse the repository at this point in the history
fix: prevent state updates in parent while rendering qrcodescanner
  • Loading branch information
im-adithya authored Nov 22, 2024
2 parents 6a6cfb0 + 9ca2546 commit 93d709b
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions components/QRCodeScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ function QRCodeScanner({
}

const handleScanned = (data: string) => {
setScanning((current) => {
if (current === true) {
console.info(`Bar code with data ${data} has been scanned!`);
onScanned(data);
return true;
}
return false;
});
if (isScanning) {
console.info(`Bar code with data ${data} has been scanned!`);
onScanned(data);
setScanning(false);
}
};

return (
Expand Down

0 comments on commit 93d709b

Please sign in to comment.