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} = React; function App() { const [elements, setElements] = useState([1, 2, 3, 4, 5, 6, 7, 8, 9]); const removeOddElements = () => { const filteredElements = elements.filter((element) => element % 2 === 0); setElements(filteredElements); }; return ( <div className='container'> <h1>React Js Remove Odd Elements from List</h1> <button onClick={removeOddElements}>Remove Odd</button> <ul> {elements.map((element, index) => ( <li key={index}>{element}</li> ))} </ul> </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; } h1 { font-size: 24px; color: #333; } button { background-color: #007BFF; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } ul { list-style: none; padding: 0; } li { font-size: 18px; margin: 5px 0; padding: 5px; background-color: #fff; border-radius: 5px; } </style> </body> </html>