screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <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> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [count, setCount] = useState(0); const [isRunning, setIsRunning] = useState(false); useEffect(() => { let interval; if (isRunning) { interval = setInterval(() => { setCount((prevCount) => prevCount + 1); }, 1000); // Update the count every second (1000 ms). } else { clearInterval(interval); } return () => clearInterval(interval); }, [isRunning]); const startCounter = () => { setIsRunning(true); }; const stopCounter = () => { setIsRunning(false); }; const resetCounter = () => { setCount(0); setIsRunning(true); }; return ( <div className='container'> <h3>React Js Counter App</h3> <p className='count-text'>Count: {count}</p> <button className='start-button' disabled={isRunning} onClick={startCounter}>Start</button> <button className='stop-button' disabled={!isRunning} onClick={stopCounter}>Stop</button> <button className='reset-button' onClick={resetCounter}>Reset</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 600px; text-align: center; background: #fff; border-radius: 5px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } /* Count text styles */ .count-text { font-size: 24px; color: #333; margin: 10px 0; } /* Button styles */ button { padding: 10px 20px; margin: 5px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; font-weight: bold; } /* Start button styles */ .start-button { background-color: #27ae60; color: #fff; } .start-button:hover { background-color: #219049; } /* Stop button styles */ .stop-button { background-color: #e74c3c; color: #fff; } .stop-button:hover { background-color: #d64131; } /* Reset button styles */ .reset-button { background-color: #3498db; color: #fff; } .reset-button:hover { background-color: #2980b9; } button:disabled { background-color: #ccc; cursor: not-allowed; } </style> </body> </html>