Q1. What features would a weather app have?
A weather app typically allows users to search for a city, displays current weather (temperature, conditions, humidity, wind), and possibly a forecast. It uses a weather API like OpenWeatherMap.
Q2. How do you fetch weather data in React?
Use useEffect to fetch data when the city changes. Use state for weather data, loading, and error. Make an API call with fetch or axios, and handle the response.
Q3. How do you handle API keys securely?
Store API keys in environment variables (REACT_APP_API_KEY). Never expose them in client-side code. For better security, use a backend proxy.
Q4. How do you display weather icons?
Most weather APIs provide icon codes. You can map them to image URLs or use icon libraries. For example, OpenWeatherMap provides icon URLs like http://openweathermap.org/img/wn/{icon}.png.
Q5. How do you implement search with debouncing?
Use a debounced input to avoid fetching on every keystroke. You can use lodash.debounce or implement your own with setTimeout and cleanup in useEffect.
