Module quiz: React Hooks and Custom Hooks Quiz Answers
In this article i am gone to share Coursera Course: Advanced React by Meta Week 2 | Module quiz: React Hooks and Custom Hooks Quiz Answers with you..
Enroll Link: Advanced React
Advanced React Coursera Quiz Answers
Also visit this link: Module quiz: Components Quiz Answers
Module quiz: React Hooks and Custom Hooks Quiz Answers
Question 1)
How is array destructuring relevant to hooks in React?
- It makes the Virtual DOM possible.
- It makes it possible to handle click events.
- It is a way to get individual items from an array of items, and save those individual items as separate components.
- It makes it possible to reassign state objects.
Question 2)
Is the following paragraph correct?
With array destructuring, you are free to give any variable name to the items that you destructure from an array. Contrary to that, when destructuring objects, you have to destructure a property of an object using that exact property’s name as the name of the destructured variable.
- Yes
- No
Question 3)
The useEffect hook is a way to:
- handle visual effects (animations and transitions) in React
- handle one-way data flows
- handle a side effect.
Question 4)
Which answer is correct about the following code snippet?
useEffect( () => { if (data !== '') { setData('test data') } })
- This code is breaking the rules of hooks
- This code is not breaking the rules of hooks
- This code is ok, except the fact that you should replace the if statement with a ternary operator.
Question 5)
Choose an example of a side-effect with which you’d need to use a useEffect hook:
- Update the value of the state variable in a child component.
- Run a Fetch API call in React.
- Render some prop values on the screen.
Question 6)
Complete the sentence:
The useState hook starts with an initial state, but…
- the useReducer hook gets a reducer function in addition to the initial state.
- the userReducer hook must be used when the initial state is an object.
- the useReducer hook cannot be used to track the state at all.
Question 7)
True or false: useRef is a custom hook in React.
- Yes
- No
Question 8)
JavaScript is a single-threaded language, meaning…
- …you can use it with React only when this single thread is passed to the useState variable.
- …you can use it with React only when this single thread is used with the useEffect hook.
- …it can only do a single thing at any given time.
Question 9)
Which statement is correct about the following code snippet:
import { useEffect } from "react"; function useConsoleLog(varName) { useEffect(() => { console.log(varName); }); } export default useConsoleLog;
Choose the correct statement below.
- This code is an example of an explicit state-updating function.
- This code is an example of an implicit state-updating function.
- This is an example of a custom hook.
Question 10)
Find the error in this code:
import {useState} from "react"; export default function App() { const [restaurantName, setRestaurantName] = function updateRestaunantName() { useRestaurantName("Litt1e Lemon"); return ( <div> <h1>{restaurantName}</h1> <button onClick={updateRestaurantName}> Update restaurant name </button> </div> ); };
- The code inside the updateRestaurantName() function definition should not invoke
useRestaurantName(“Little Lemon”) - The state-setting function’s variable name in the array destructuring should not be setRestaurantName.
- The onClick event should not be this:
onClick={updateRestaurantName}