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 [options, setOptions] = useState([ 'KGF', '3 IDIots', 'Yaar ka Sataya Hua', 'Sholay', 'Dilwale Dulhania Le Jayenge', 'Baahubali', 'Lagaan', 'Golmaal', 'Dangal', 'Queen' ]); const [selectedOption, setSelectedOption] = useState('Option 1'); const removeOption = () => { const updatedOptions = options.filter((option) => option !== selectedOption); setOptions(updatedOptions); setSelectedOption(updatedOptions[0]); // Select the first option after removal }; return ( <div className='container'> <h3>React Js Remove options from select list</h3> <select className='custom-select' value={selectedOption} onChange={(e) => setSelectedOption(e.target.value)}> {options.map((option) => ( <option key={option} value={option} className='custom-option'> {option} </option> ))} </select> <button className='custom-button' onClick={removeOption}>Remove Selected Option</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); max-width: 600px; margin: 0 auto; text-align: center; } /* Custom Select */ .custom-select { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; outline: none; font-size: 16px; } /* Custom Option */ .custom-option { font-size: 16px; } /* Custom Button */ .custom-button { background-color: #007bff; color: #fff; padding: 10px 20px; border: none; border-radius: 4px; margin-top: 10px; cursor: pointer; transition: background-color 0.3s; } .custom-button:hover { background-color: #0056b3; } </style> </body> </html>