21. Complete the sentence:

The useState hook starts with an initial state, but...

  • the useReducer hook cannot be used to track the state at all.
  • the userReducer hook must be used when the initial state is an object.
  • the useReducer hook gets a reducer function in addition to the initial state.

22. True or false: useRef is a custom hook in React.

  • Yes
  • No

23. JavaScript is a single-threaded language, meaning...

  • …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.
  • …you can use it with React only when this single thread is passed to the useState variable.

24. 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 is an example of a custom hook.
  • This code is an example of an explicit state-updating function.
  • This code is an example of an implicit state-updating function.

25. Find the error in this code:

import {useState} from "react";

export default function App() {
const [restaurantName, setRestaurantName] = useState("Lemon");

function updateRestaurantName() {
useRestaurantName("Little Lemon");
};

return (
< div>
< h1>{restaurantName}< /h1>
< button onClick={updateRestaurantName}>
Update restaurant name
< /button>
< /div>
);
};

  • The onClick event should not be this:

    onClick={updateRestaurantName}

  • 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.

Leave a Reply