Chapter 9: Rules of Hooks

  1. Where can Hooks be called?
    • Hooks can only be called at the beginning of React function components or custom Hooks
  2. Can we use Hooks in React class components?
    • No, it is not possible to use Hooks in React class components
  3. What do we need to watch out for regarding the order of Hooks?
    • The order of Hooks should never change, as it is used to track the values of various Hooks
  4. Can hooks be called inside conditions, loops, or nested functions?
    • No, Hooks cannot be called inside conditionals, loops, or nested functions, because that would change the order of Hooks
  5. What is the naming convention for Hooks?
    • Hook function names should always start with a use prefix and then a name in CamelCase. For example: useSomeHookName.
  1. How can we automatically enforce the rules of Hooks?
    • We can use eslint with eslint-plugin-react-hooks to enforce the rules of Hooks
  2. What is the exhaustive dependencies rule?
    • The exhaustive dependencies rule ensures that in an Effect Hook all variables that are used are listed as dependencies via the second argument
  3. How can we automatically fix linter warnings?
    • We can run the npm run lint -- --fix command to automatically fix linter warnings. Running this command will, for example, automatically enter all variables used in an Effect Hook as dependencies.
..................Content has been hidden....................

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