screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.14.6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel" data-presets="env,react"> const { useState, useEffect, useRef } = React; function App() { const [inputString, setInputString] = useState("aabbcc"); const [compressedString, setCompressedString] = useState(""); const compressString = () => { let compressed = inputString.replace( /(.)\1+/g, (match, char) => `${char}${match.length}` ); setCompressedString(compressed); }; return ( <div class='container'> <h2>React Js Compress string</h2> <input type="text" value={inputString} onChange={(e) => setInputString(e.target.value)} placeholder="Enter a string" /> <button onClick={compressString}>Compress</button> <p>Original String: {inputString}</p> {compressedString ? ( <p>Compressed String: {compressedString}</p> ) : ( <p>No compressed string available.</p> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { text-align: center; margin-top: 50px; } h2 { color: #333; margin-bottom: 20px; } input[type="text"] { padding: 10px; width: 200px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; } button { padding: 10px 20px; background-color: #333; color: #fff; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #555; } p { margin-top: 10px; font-size: 16px; color: #333; } </style> </body> </html>