screen_rotation
Copied to Clipboard
<!DOCTYPE html> <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 } = React; function App() { const [buttonText, setButtonText] = useState("Click me"); const changeButtonText = () => { buttonText === "Click me" ? setButtonText("Button clicked!") : setButtonText("Click me"); }; return ( <div> <h3>React JS Change Button Text on click</h3> <button onClick={changeButtonText}>{buttonText}</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> button { background-color: #4caf50; /* Green */ border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; } </style> </body> </html>