MCQs on our Weather App

MCQs on our Weather App

1. Which React Hook lets you store and update state in functional components?
a. useEffect
b. useReducer
c. useState
d. useContext

2. What is the purpose of the useEffect hook in the TimeDisplay component?
a. Handle user input
b. Perform side-effects like setting intervals
c. Add CSS styles
d. None of the above

3. What happens if the city entered is not found?
a. App crashes
b. Nothing happens
c. A default city is shown
d. An error message is displayed

4. Why do we include setLoading(true) and setLoading(false) in handleSearch?
a. To show a loading spinner or message during fetch
b. To prevent React errors
c. To avoid rendering
d. To style the app

5. What is the primary role of SearchBar.js?
a. Display the temperature
b. Render the weather card
c. Accept user input and pass it to the parent
d. Call the weather API directly

Answer Key:

Question

Answer

Explanation

Q1auseState is a React Hook that lets you add state to functional components. It returns an array with two elements: the state and the function to update it.
Q2bgetWeatherByCity is an async function, so await is necessary to pause execution until it returns the fetched weather data.
Q3cThe condition {weatherData && <WeatherCard data={weatherData} />} ensures the component renders only when weatherData has a truthy value.
Q4cThe onSearch prop in SearchBar is a function, which is invoked in SearchBar using onSearch(city) when the user submits a city.
Q5bThe footer uses an anchor tag (<a>) to link to GUVI's website and includes attributes target="_blank" and rel="noreferrer" for safe new-tab behavior.