Chapter 5: Implementing React Context

  1. Which problem do contexts avoid?
    • Contexts avoid having to pass down props through multiple levels of components
  2. What are the two parts that contexts consist of?
    • React contexts consist of a provider and a consumer
  3. Are both parts required to be defined in order to use contexts?
    • The provider is not required, as contexts will use the default value passed to React.createContext when no provider is defined
  4. What is the advantage of using Hooks instead of traditional context consumers?
    • Hooks do not require using a component and render props for the consumer. Using multiple contexts with consumer components makes our component tree very deep and our app harder to debug and maintain. Hooks avoid this problem by allowing us to consume contexts by simply calling a Hook function.
  5. What is an alternative to contexts, and when should we use it?
    • Contexts make reusing components more difficult. Contexts should only be used when we need to access data in multiple components at different nesting levels. Otherwise, we can either pass down props or pass down the rendered component, using a technique called inversion of control.
  6. How can we implement dynamically changing contexts?
    • We need to use a State Hook to provide the value for the context provider
  1. When does it make sense to use contexts for state?
    • Usually, it makes sense to use contexts for global state, which is used across multiple components at different nesting levels
..................Content has been hidden....................

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