code a simple travel app in react
- User
code a simple travel app in react
- Assistant
I'll provide you with a basic structure of a travel app using React. This app will display a list of travel destinations and allow the user to select one to view more information about it.
First, let's create a new React app:
bashnpx create-react-app travel-app cd travel-appNow, replace the contents of
src/App.jswith the following code:javascriptimport React, { useState } from 'react'; const destinations = [ { id: 1, name: 'Paris, France', image: 'https://source.unsplash.com/1600x900/?paris', description: 'Paris is known as the City of Light because it was one of the first cities to adopt street lighting. It is also known for its beautiful architecture, art museums, and delicious food.' }, { id: 2, name: 'New York, USA', image: 'https://source.unsplash.com/1600x900/?new-york', description: 'New York City is a major cultural, financial, and media center of the world. Famous for its skyscrapers, including the Empire State Building and the Statue of Liberty.' }, { id: 3, name: 'Tokyo, Japan', image: 'https://source.unsplash.com/1600x900/?tokyo', description: 'Tokyo is the capital of Japan and the largest metropolitan area in the world. It is known for its modern design, technology, and pop culture.' } ]; function App() { const [selectedDestination, setSelectedDestination] = useState(null); const handleDestinationClick = (destination) => { setSelectedDestination(destination); }; return ( <div className="App"> <h1>Travel App</h1> <h2>Select a destination:</h2> <ul> {destinations.map((destination) => ( <li key={destination.id} onClick={() => handleDestinationClick(destination)}> {destination.name} </li> ))} </ul> {selectedDestination && ( <> <h2>{selectedDestination.name}</h2> <img src={selectedDestination.image} alt={selectedDestination.name} /> <p>{selectedDestination.description}</p> </> )} </div> ); } export default App; - User
Continue writing please
- Assistant
To continue building on the basic travel app, let's add some additional features:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.