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> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [showDiv, setShowDiv] = useState(true); useEffect(() => { // Hide the div after 5 seconds const timeoutId = setTimeout(() => { setShowDiv(false); }, 5000); // 5000 milliseconds (5 seconds) // Clear the timeout to prevent it from running if the component unmounts return () => clearTimeout(timeoutId); }, []); return ( <div className='container'> <h3>React Js Div Hide After 5 Seconds</h3> {showDiv && ( <div style={{ border: '1px solid green' , padding:'16px' }}> This Div Automatically Hides After 5 Seconds </div> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> /* Container Styles */ .container { margin: 20px; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); background-color: #fff; } </style> </body> </html>