screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.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; const countryData = [ { name: 'Australia', description: 'Australia is a country and continent surrounded by the Indian and Pacific oceans.', }, { name: 'Germany', description: 'Germany is a country located in central Europe known for its rich history and cultural heritage.', }, { name: 'Brazil', description: 'Brazil is the largest country in South America, known for its diverse culture and the Amazon rainforest.', }, { name: 'China', description: 'China is a populous country in East Asia known for its ancient civilization and rapid modernization.', }, { name: 'India', description: 'India is a country in South Asia known for its diverse culture, ancient history, and vibrant traditions.', }, { name: 'Japan', description: 'Japan is an island country in East Asia known for its technological advancements and unique culture.', }, { name: 'South Africa', description: 'South Africa is a country at the southernmost tip of Africa, known for its diverse landscapes and wildlife.', }, // Add more countries and descriptions as needed ]; const App = () => { const [selectedCountry, setSelectedCountry] = useState(''); // State to track the selected country // Event handler to update the selectedCountry state when dropdown selection changes const handleDropdownChange = (event) => { const selectedValue = event.target.value; setSelectedCountry(selectedValue); }; // Find the selected country object from the data const selectedCountryData = countryData.find((country) => country.name === selectedCountry); return ( <div className='container'> <h3>React Js Show Hide Div Based on Dropdown Selection using Map Method</h3> {/* Dropdown */} <select onChange={handleDropdownChange}> <option value="">Select a country</option> {countryData.map((country) => ( <option key={country.name} value={country.name}> {country.name} </option> ))} </select> {/* Div to display country information */} {selectedCountryData && ( <div> <h3>{selectedCountryData.name}</h3> <p>{selectedCountryData.description}</p> </div> )} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Styles for the container and button */ .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } /* Styling for the select element */ .container select { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; outline: none; } /* Styling for the option elements */ .container option { font-size: 16px; } button { background-color: #007bff; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } /* Hover effect for the button */ button:hover { background-color: #0056b3; } </style> </body> </html>