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 } = React; function App() { // Create a state variable to track the toggle state const [isToggled, setIsToggled] = useState(true); // Function to toggle the state const toggleText = () => { setIsToggled(!isToggled); }; // Define the text content based on the toggle state const textToShow = isToggled ? "Font Awesome Icons" : "Tutorials Plane"; return ( <div className='container'> <h3 className='heading'>React Js Toggle Text</h3> <button className='toggle-button' onClick={toggleText}>Toggle Text</button> <p className='text'>{textToShow}</p> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Style the container */ .container { max-width: 400px; margin: 0 auto; padding: 20px; text-align: center; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } /* Style for the heading */ .heading { font-size: 24px; color: #333; margin-bottom: 20px; } /* Style for the toggle button */ .toggle-button { background-color: #007bff; color: #fff; border: none; padding: 10px 20px; font-size: 18px; cursor: pointer; border-radius: 5px; transition: background-color 0.3s ease; } .toggle-button:hover { background-color: #0056b3; } /* Style for the text */ .text { font-size: 18px; margin-top: 20px; color: #444; } </style> </body> </html>