-
-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nextjs Only 1 Instance problem #200
Comments
I have the same issue. No solution found yet |
I found a way to deal with it. Instead of svg, we'll use canvas. By some chance the library can't separate the different information for each svg, so they'll have the same value, and by switching to rendering with canvas we won't have this problem. In addition, I've also allocated to instantiate the qrcode class inside the component function, thus creating a separate instance for each qrcode, avoiding replicating the qrcode values. My code below: src/app/page.tsx "use client";
import * as S from './styles';
import QRCodeStyling from 'qr-code-styling';
interface Props {
value: string;
}
const QRCode = ({ value }: Props) => {
const qrCode = new QRCodeStyling({
width: 500,
height: 500,
type: 'canvas',
backgroundOptions: {
color: 'transparent',
},
dotsOptions: {
color: '#4267b2',
type: 'rounded',
},
data: value,
});
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!ref || !ref.current) return;
qrCode.update({
data: value,
});
}, [value]);
useEffect(() => {
if (!ref || !ref.current) return;
qrCode.append(ref.current);
}, []);
return <S.Qrcode ref={ref} />;
};
export default function Page() {
return (
<S.Container>
hi
<QRCode value={'01011010100101'} />
other
<QRCode value={'awdawddawdawd'} />
</S.Container>
);
}; |
Hi @Jervx @vezhdelit @korizyx the issue with 2 qr-codes on the same page was fixed in version v1.7.1 and above. |
I have this code, then I called it 2x somewhere
I called it 2x here
it only shows the last one
when I removed the last
<QRCode value={'a different one'}/>
this is the resultHow can I prevent this from happening?
The text was updated successfully, but these errors were encountered: