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 [items, setItems] = useState(['item1', 'item2', 'item3', 'item4']); const removeItemByIndex = (index) => { const updatedItems = [...items]; updatedItems.splice(index, 1); setItems(updatedItems); }; return ( <div className='container'> <h3>React Js Remove Item from array by Index</h3> <h1>Items List</h1> <ul> {items.map((item, index) => ( <li key={index}> {item} <button onClick={() => removeItemByIndex(index)}>Remove</button> </li> ))} </ul> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { font-family: Arial, sans-serif; text-align: center; margin: 2rem auto; padding: 1.5rem; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); border-radius: 8px; background-color: #ffffff; max-width: 400px; } h3 { font-size: 1.2rem; color: #333333; } h1 { font-size: 2rem; color: #333333; margin-top: 1.5rem; } ul { margin-top: 1.5rem; } li { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 1rem; border-bottom: 1px solid #dddddd; } button { padding: 0.3rem 0.5rem; background-color: #ff6347; color: #ffffff; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #d43f00; } </style> </body> </html>