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 { useRef } = React; function App() { const buttonRef = useRef(null); const handleButtonClick = () => { // Your button click logic here }; const disableButton = () => { buttonRef.current.disabled = true; }; const enableButton = () => { buttonRef.current.disabled = false; }; return ( <div className='container'> <h3>React Js Disable Button using useref</h3> <button ref={buttonRef} onClick={handleButtonClick}> Click Me </button> <button onClick={disableButton}>Disable Button</button> <button onClick={enableButton}>Enable Button</button> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Container */ .container { display: flex; flex-direction: column; align-items: center; justify-content: center; background-color: #f4f4f4; font-family: Arial, sans-serif; } /* Styles for the h3 header */ h3 { font-size: 24px; color: #333; margin-bottom: 20px; } /* Styles for the buttons */ button { padding: 10px 20px; font-size: 16px; margin: 5px; border: none; cursor: pointer; border-radius: 5px; transition: background-color 0.3s, color 0.3s; } button:hover { background-color: #333; color: #fff; } /* Style for the disabled button */ button[disabled] { background-color: #ccc; color: #666; cursor: not-allowed; } </style> </body> </html>