Hard
Users of a weather dashboard application are reporting that sometimes the wrong city's weather is displayed. The following code is responsible for fetching and displaying weather data. What's the critical bug in this implementation?
1class WeatherDashboard extends React.Component {2 state = {3 weatherData: null,4 selectedCity: null,5 error: null6 };78 async fetchWeatherData(city) {9 try {10 const response = await fetch(11 `https://api.weather.com/v1/${city}?apikey=12345`12 );13 const data = await response.json();14 this.setState({15 weatherData: data,16 error: null17 });18 } catch (err) {19 this.setState({ error: err.message });20 }21 }2223 handleCitySelect = (city) => {24 this.setState({ selectedCity: city });25 this.fetchWeatherData(city);26 };2728 render() {29 const { weatherData, error } = this.state;30 return (31 <div>32 <CitySelector onSelect={this.handleCitySelect} />33 {error ? (34 <ErrorMessage message={error} />35 ) : (36 <WeatherDisplay data={weatherData} />37 )}38 </div>39 );40 }41}