import QRCode from 'qrcode.react'; import { useEffect, useRef, useState } from 'react'; import './style.css'; export const Card = () => { const firstLoad = useRef(true); const [qrvalue, setQrvalue] = useState(''); const [network, setNetwork] = useState({ ssid: '', password: '', }); const [portrait, setPortrait] = useState(false); const escape = (v) => { const needsEscape = ['"', ';', ',', ':', '\\']; let escaped = ''; for (let i = 0; i < v.length; i++) { let c = v[i]; if (needsEscape.includes(c)) { c = '\\' + c; } escaped += c; } return escaped; }; const onPrint = () => { if (network.password.length < 8) { alert('Password must be at least 8 characters'); } else { window.print(); } }; useEffect(() => { if (firstLoad.current && window.innerWidth < 500) { firstLoad.current = false; setPortrait(true); } const ssid = escape(network.ssid); const password = escape(network.password); setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`); }, [network]); return (