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() { // Step 2: Initialize a state variable for click count const [clickCount, setClickCount] = useState(0); const maxClicks = 3; // Set your desired maximum number of clicks here // Step 3: Event handler to increment click count const handleClick = () => { // Increment click count setClickCount(clickCount + 1); }; // Step 4: Disable the button when clickCount exceeds maxClicks const isButtonDisabled = clickCount >= maxClicks; return ( <div className='container'> <h3>React Js Disabled Button After some Click</h3> <button onClick={handleClick} disabled={isButtonDisabled}> {isButtonDisabled ? 'Button Disabled' : 'Click Me'} </button> <p>Click Count: {clickCount}</p> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { width: 600px; margin: 0 auto; box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px -1px, rgba(0, 0, 0, 0.06) 0px 2px 4px -1px; padding: 20px; } /* Style the button */ button { background-color: #007bff; color: #fff; border: none; padding: 10px 20px; font-size: 16px; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } button:disabled { background-color: #ccc; cursor: not-allowed; } </style> </body> </html>