I managed to copy the generated UUID into my clipboard but whenever I click on the button, the UUID (and QR code) changes even though the page did not refresh. How to prevent the UUID from changing its state? Please refer to the codes below;
import React, { useState } from "react";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import FileCopyIcon from "@material-ui/icons/FileCopy";
import { v4 as uuid } from "uuid";
import QRCode from "react-qr-code";
import { CopyToClipboard } from "react-copy-to-clipboard";
export default function QRGenerator() {
const adminId = uuid();
const [qrcode, setQrcode] = useState({
value: "",
copied: false,
});
return (
<div>
<CopyToClipboard
text={adminId}
onCopy={() => setQrcode({ copied: true })}
>
<Button>
<FileCopyIcon />
</Button>
</CopyToClipboard>
<Typography align="center" variant="caption" paragraph="true">
Admin ID : {adminId}
{qrcode.copied ? <span style={{ color: "red" }}>Copied.</span> : null}
</Typography>
<QRCode value={adminId} />
</div>
);
}