Guest User

Untitled

a guest
May 20th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. # Compound Components
  2.  
  3. * Give quick overview of current Navigation usage
  4.  
  5. * Pose question "Why are we defining our own API?"
  6. * Why not just use React's component API?
  7.  
  8. * Go over Navigation implementation
  9.  
  10. * Point out that the reason we're using our own object API
  11. is because there is "implicit state"
  12. * We want the Navigation component to handle the "active route"
  13. state without the user having to know about it/handle it
  14.  
  15. * Go back to Navigation use, pose question "What happens when we want to
  16. to render something that isnt a Nav Item"?
  17. * Explain how using our own API, instead of React's component API,
  18.  
  19. limits how dynamic (and useful) our component can be
  20.  
  21. * This is where compound components come in!
  22.  
  23. * Component components are a pattern where you can pass in *implicit* state between two components.
  24.  
  25. * Compound components let you share implicit state without having to break out of React's component model
  26.  
  27. * Implement a NavigationItem component, export as Navigation.Item
  28. * Explain how using static properties can be a good way to couple
  29. compound components so it's obvious that they must be used together.
  30.  
  31. * First implementation will display the navigation items correctly, but
  32. the active state will not work.
  33.  
  34. * Implement Navigation.Split, another cool example of compound components
  35.  
  36. * Render the Logo and SearchBar too, to show off how you can render any components now. Shuffle them around, show how easy it is
  37.  
  38.  
  39. * Circle back to implicit state. Compound component API is cool and readable, but the point is to share implicit state. How do we do that?
  40.  
  41. * Start with React.Children.map and React.cloneElement implementation
  42.  
  43. * Explain how cloneElement can let you pass in additional props to a child components, which is a good solution for implicit state.
  44.  
  45. * Show it working with React.cloneElement
  46.  
  47. * Put the active Navigation.Item inside a div, show how it breaks the implicit state
  48.  
  49. * Explain why this is, how React.cloneElement is now passing in the implicit state to the wrong component
  50.  
  51. * Move on to React Context solution
  52.  
  53.  
  54. # Controlled Components
  55.  
  56. * Go over RadioGroup component and implementation
  57.  
  58. * Point out how currently, the input state is _uncontrolled_
  59.  
  60. * Discuss how we're probably all familiar with _controlled_ and
  61. _uncontrolled_ inputs.
  62.  
  63. * The idea with controlled inputs is that we can manage the state
  64. of the input in React, instead of the DOM. We have full control over it
  65.  
  66. * Make RadioGroup a controlled component. Use React context.
  67. * Show off memoize-one for getContext! Cool strategy
  68.  
  69. * Talk about the advantages of controlled inputs.
  70. * RadioGroup is in total control of the value being rendered, meaning
  71. it can implement any restrictions, side-effects, or behavior that
  72. it wants based on the current value
  73.  
  74. * You could also store the state somewhere else (like Redux) if you wanted
  75.  
  76. * These same advantages extend to other components that manage some
  77. kind of state
  78.  
  79. * Refactor RadioGroup to accept a value and onChange prop
  80.  
  81. * Show how, with a controlled compound component, we get the advantage of
  82. controlling the state we care about (the value) but also the advantage
  83. of not having to be explicit about the state we _dont_ care about.
  84. * i.e, passing the `checked` state to each option.
  85.  
  86.  
  87. # Higher Order Components
  88.  
  89. * Go over Network Status application
  90.  
  91. * Show how Online and Offline are duplicating a lot of logic
  92.  
  93. * Suggest that we could use the compound component pattern we learned
  94. * Point out that compound components require a single shared parent
  95. to manage and provide that implicit state
  96.  
  97. * We want to use Offline and Online separately
  98.  
  99. * One option for shared logic between independant components is
  100. higher-order components
  101.  
  102. * Make sure class is clear on the terminology of "higher order component"
  103. * show a higher order function if necessary
  104.  
  105. * Explain that HOC is a weird term because it's not "really" a higher-
  106. oreder function. It's a factory function that returns a new component
  107.  
  108. * Implement a `withOnlineStatus` HOC
  109.  
  110. * Make sure it sets the correct display name
  111.  
  112. * Forward refs
  113.  
  114. * Hoist statics
Add Comment
Please, Sign In to add comment