screen_rotation
Copied to Clipboard
<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://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect, useRef } = React; function App() { const [message, setMessage] = useState(""); useEffect(() => { const interval = setInterval(() => { setMessage(new Date().toLocaleTimeString()); }, 1000); return () => clearInterval(interval); }, []); return ( <div id="app"> <h3>React Js setInterval Method</h3> <p>Use of setTimeout in React Js</p> <p>{message}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> #app { text-align: center; margin-top: 20px; } h3 { color: #333; font-size: 24px; font-weight: bold; } p { color: #777; font-size: 18px; margin-top: 10px; } </style> </body> </html>