screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <div id="app"></div> <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://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> <script type="text/babel"> const { useState } = React; function App() { const [text, setText] = useState('Welcome to fontawesomeicons'); const [searchTerm, setSearchTerm] = useState('welcome'); const [replaceTerm, setReplaceTerm] = useState('Thanks for visting'); const handleTextChange = (event) => { setText(event.target.value); }; const handleSearchTermChange = (event) => { setSearchTerm(event.target.value); }; const handleReplaceTermChange = (event) => { setReplaceTerm(event.target.value); }; const handleReplace = () => { setText(text.replace(new RegExp(searchTerm, 'gi'), replaceTerm)); alert('Replaced successfully') }; return ( <div className='container'> <h3>React Js Find and Replace Method</h3> <textarea value={text} onChange={handleTextChange} /> <label>Find Text</label> <input type="text" placeholder="Search term" value={searchTerm} onChange={handleSearchTermChange} /> <label>replace text</label> <input type="text" placeholder="Replace term" value={replaceTerm} onChange={handleReplaceTermChange} /> <button onClick={handleReplace}>Replace</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 500px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } textarea { width: 100%; height: 200px; padding: 10px; margin-bottom: 10px; resize: none; } label { font-weight: bold; margin-bottom: 5px; } input[type="text"] { width: 100%; padding: 8px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; } button { padding: 10px 20px; background-color: #4caf50; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } </style> </body> </html>