front-end developer capstone coursera week 3 quiz answers
Knowledge check: Table booking system
1. What is the purpose of the useState hook in React?
- To manage the component’s context
- To bind a value to the props of a component.
- To bind an event handler to an element.
- To manage the component’s state
2. What is missing from the code below?
import { useState } from "react";
export default function App() {
const [restaurantName, setRestaurantName] = useState();
return < h1>{restaurantName}< /h1>;
}
- An initial value for the state variable restaurantName
- The setRestaurantName function.
- The useState hook import statement
- useReducer hook was not used
4. What is unit testing in React?
- A type of testing that ensures that a complete application is working as intended.
- A type of testing that ensures that a component’s props and state are correctly being passed down to its children.
- A type of testing that involves manually testing a component’s UI.
- A type of testing that ensures that individual units of code are working as intended.
5. What is the main difference between the useState and useReducer hooks in React?
- useState is used for managing component state, while useReducer is used for managing the component’s UI.
- useState is used for simple state updates, while useReducer is used for complex state updates.
- useState is used for managing component state, while useReducer is used for managing the component lifecycle.
- useState is used for managing component state, while useReducer is used for managing global state.
Knowledge check: Interacting with the API
6. Why should you never call hooks inside a nested function in react?
- To avoid unnecessary re-renders of the component
- To prevent memory leaks
- To ensure that the component updates correctly
- Because hooks can only be called from the top level of a function component
7. True or false. The fetch function should be used inside the componentDidMount lifecycle method or useEffect hook.
- True
- False
8. When you receive a HTTP response using the fetch() API, how do you parse the data into a JavaScript object?
- The fetch() API automatically parses the response data as a JSON object.
- You should use the JSON.parse() method to parse the response data as a JSON object.
- You should use the json() method of the response object to parse the data as a JSON object.
- You should use the text() method of the response object to parse the data as a JSON object
Shuffle Q/A 1
9. Which of the following statements are true? Choose all that apply.
- You can load local JSON files in your React project
- The fetch() API call cannot make DELETE request
- If the external API returns JSON data, you need to exclusively parse it in the fetch() API
- You cannot make multiple fetch() calls in the useEffect hook
10. Complete the sentence: JSON is ______________.
- A file format and a data exchange format
- Only a data exchange format
- Only a file format