Skip to content

Commit

Permalink
fix: prevent state updates in parent while rendering qrcodescanner
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Nov 19, 2024
1 parent 6e51fa7 commit 9ca2546
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 9ca2546

Please sign in to comment.