forked from rohitagr0310/Bookflow-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarCode.jsx
48 lines (44 loc) · 1.41 KB
/
BarCode.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { useState, useRef } from "react";
import Webcam from "react-webcam";
import { Button, Container, Typography, Paper } from "@material-ui/core";
function BarCode () {
const webcamRef = useRef(null);
const [scannedData, setScannedData] = useState("");
const handleScan = () => {
const imageSrc = webcamRef.current.getScreenshot();
// Implement barcode decoding logic here
// Set the scannedData state with the decoded data
setScannedData("Decoded data from image: " + imageSrc);
};
return (
<Container maxWidth="sm" style={{ marginTop: "50px" }}>
<Paper elevation={3} style={{ padding: "20px" }}>
<Typography variant="h4" gutterBottom>
Barcode Reader
</Typography>
<Webcam
audio={false}
ref={webcamRef}
screenshotFormat="image/jpeg"
width={400}
style={{ marginBottom: "20px" }}
/>
<Button
variant="contained"
color="primary"
onClick={handleScan}
fullWidth
>
Scan Barcode
</Button>
{scannedData && (
<div style={{ marginTop: "20px" }}>
<Typography variant="h6">Scanned Data:</Typography>
<Typography variant="body1">{scannedData}</Typography>
</div>
)}
</Paper>
</Container>
);
}
export default BarCode;