"import user";
import { Button } from "@/components/ui/button";
import QRCodeStyling from "qr-code-styling";
import { useEffect, useState } from "react";
const ShareButton = ({ recipe }: any) => {
const [qrPopupIsOpen, setQrPopupIsOpen]: any = useState(false);
const [qrCode, setQRCodeInstance] = useState<QRCodeStyling | null>(
null
);
useEffect(() => {
if (qrPopupIsOpen) {
const qrCode = new QRCodeStyling({
width: 300,
height: 300,
backgroundOptions: {
color: "transparent",
},
dotsOptions: {
type: "classy-rounded",
},
data: `/recipes/${recipe.id}`,
imageOptions: {
crossOrigin: "anonymous",
margin: 20,
},
});
setQRCodeInstance(qrCode);
}
}, [qrPopupIsOpen]);
const toggleQrPopup = () => {
setQrPopupIsOpen(!qrPopupIsOpen);
};
const openSharePopup = () => {
toggleQrPopup();
};
return (
<div>
<Button variant="outline" className="w-full" onClick={openSharePopup}>
Share
</Button>
{qrPopupIsOpen && qrCode && (
<div className="fixed top-0 left-0 w-full h-screen flex items-center justify-center bg-neutral-950/25 backdrop-blur-sm z-[999]">
<div className="bg-neutral-200 p-8 rounded-xl relative max-w-[90vw] max-h-[90vh] overflow-auto">
<button
className="absolute top-4 right-4 text-gray-600 hover:text-gray-800"
onClick={toggleQrPopup}
>
<p>close</p>
</button>
<div
className="bg-transparent"
ref={(node) => node && qrCode?.append(node)}
/>
</div>
</div>
)}
</div>
);
};
export default ShareButton;
I encountered an issue with a status 500 error code and the message "self is not defined" in the console. Although my code executes correctly on the UI, this error persists.
The primary goal is to display a QR code within a popup without encountering any console errors.
GET /recipes 500 in 397ms
⨯ ReferenceError: self is not defined
at __webpack_require__ (/Users/yevheniiasimaka/Desktop/recipe-website/.next/server/webpack-runtime.js:33:43)
Despite efforts to resolve the issue by wrapping the code in useEffect as recommended, the "self is not defined" error remains persistent. This problem arose while developing a recipe website with a QR code sharing feature.