screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; const App = () => { const [userInput, setUserInput] = useState('https://fontawesomeicons.com'); const [qrCodeImageSrc, setQRCodeImageSrc] = useState(''); const generateQRCode = () => { axios({ method: 'GET', url: 'https://api.qrserver.com/v1/create-qr-code/', params: { data: userInput, size: '200x200', margin: '0' }, responseType: 'arraybuffer' }) .then(response => { const imageSrc = URL.createObjectURL(new Blob([response.data])); setQRCodeImageSrc(imageSrc); }) .catch(error => { console.log(error); }); }; return ( <div className='container'> <h3>React Generate QR Code</h3> <div className="form-group"> <label htmlFor="input">Enter text:</label> <input id="input" type="text" value={userInput} onChange={(e) => setUserInput(e.target.value)} /> <button onClick={generateQRCode}>Generate QR Code</button> </div> <div className="qr-code-container"> {qrCodeImageSrc && <img src={qrCodeImageSrc} alt="QR Code" />} </div> </div> ); }; ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); width: 600px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; } h3 { font-size: 24px; margin-bottom: 15px; } input { width: 100%; padding: 10px; margin: 5px 0; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; } button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } </style> </body> </html>