Knowledge check: Advanced Hooks

11. True or false: useReducer is a reducer function that takes in the initial state and an action and returns the new state.

  • True
  • False

12. True or false: The useState hook is best suited for complex state logic or when the next state depends on the previous one.

  • True
  • False

13. A common scenario for using the useRef hook is to...

  • …focus the cursor into an input field.
  • …control a component’s state.
  • …handle side effects.
  • …memorize expensive operations.

14. True or false: Building your own Hooks lets you extract component logic into reusable functions

  • True
  • False

15. The useState hook gives us a reliable way to...

  • … deal with state updates in React components.
  • … deal with state updates in React prompts.
  • … deal with state updates in React dependency arrays.
  • … deal with state updates in React useEffect invocations.

Module quiz: React Hooks and Custom Hooks

16. How is array destructuring relevant to hooks in React?

  • It makes the Virtual DOM possible.
  • It makes it possible to reassign state objects.
  • 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.

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

18. The useEffect hook is a way to:

  • handle visual effects (animations and transitions) in React
  • handle one-way data flows
  • handle a side effect.

Shuffle Q/A 2

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

20. 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.
  • Render some prop values on the screen.
  • Run a Fetch API call in React.

Leave a Reply