Chapter 8: Using Community Hooks

  1. Which Hook can we use to simplify input field handling?
    • We can use the useInput Hook from the react-hookedup library
  2. How are the componentDidMount and componentWillUnmount life cycles implemented using Effect Hooks?
    • componentDidMount can be implemented by using an Effect Hook with an empty array passed as the second argument. For example, useEffect(() => console.log('did mount'), []).
  • componentWillUnmount can be implemented by returning a function from an Effect Hook with an empty array passed as the second argument, for example, useEffect(() => { return () => console.log('will unmount') }, []).
  1. How can we use Hooks to get the behavior of this.setState()?
    • this.setState() merges the existing state object with the given state object. We can get the same behavior by using the useMergeState Hook instead of a simple State Hook.
  2. Why should we use timer Hooks instead of calling setTimeout and setInterval directly?
    • When defining simple timeouts or intervals they are going to reset when the component re-renders. To prevent this resetting from happening, we have to use the useTimeout and useInterval Hooks from react-hookedup instead.
  1. Which Hooks can we use to simplify dealing with common data structures?
    • We can use the useBoolean, useArray, and useCounter Hooks from react-hookedup
  2. When should we use responsive design with Hooks versus simply using CSS media queries?
    • We should use Hooks for responsive design when rendering elements within a canvas or WebGL, or when we dynamically want to decide whether to load components based on the window size
  3. Which Hook can we use to implement undo/redo functionality?
    • We can use the useUndo Hook from the use-undo library to implement simple undo/redo functionality in our app
  4. What is debouncing? Why do we need to do it?
    • Debouncing means that a function will only be called after a certain amount of time, not every time an event triggers it. Using debouncing, we can store a value entered in a text field in the undo history only after each second, not after every typed character.
  5. Which Hook can we use for debouncing?
    • We can use the useDebounce or the useDebouncedCallback Hook from the use-debounce library
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.211.66