File tree Expand file tree Collapse file tree 6 files changed +33
-6
lines changed
Expand file tree Collapse file tree 6 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ Elaborate on your learnings here in `src/exercise/01.md`
66
77## Background
88
9+ ** One liner:** The Context Module Functions Pattern allows you to encapsulate a
10+ complex set of state changes into a utility function which can be tree-shaken
11+ and lazily loaded.
12+
913Let's take a look at an example of a simple context and a reducer combo:
1014
1115``` javascript
@@ -91,12 +95,14 @@ context. Let's do that. You'll notice that we have to put it in
9195` React .useCallback ` so we can list our "helper" functions in dependency lists):
9296
9397` ` ` javascript
94- const increment = React .useCallback (() => dispatch ({type: ' increment' }), [
95- dispatch,
96- ])
97- const decrement = React .useCallback (() => dispatch ({type: ' decrement' }), [
98- dispatch,
99- ])
98+ const increment = React .useCallback (
99+ () => dispatch ({type: ' increment' }),
100+ [dispatch],
101+ )
102+ const decrement = React .useCallback (
103+ () => dispatch ({type: ' decrement' }),
104+ [dispatch],
105+ )
100106const value = {state, increment, decrement}
101107return < CounterContext .Provider value= {value} {... props} / >
102108
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ Elaborate on your learnings here in `src/exercise/02.md`
66
77## Background
88
9+ ** One liner:** The Compound Components Pattern enables you to provide a set of
10+ components that implicitely share state for a simple yet powerful declarative
11+ API for reusable components.
12+
913Compound components are components that work together to form a complete UI. The
1014classic example of this is ` <select> ` and ` <option> ` in HTML:
1115
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ Elaborate on your learnings here in `src/exercise/03.md`
66
77## Background
88
9+ ** One liner:** The Flexible Compound Components Pattern is only differs from the
10+ previous exercise in that it uses React context. You should use this version of
11+ the pattern more often.
12+
913Right now our component can only clone and pass props to immediate children. So
1014we need some way for our compound components to implicitly accept the on state
1115and toggle method regardless of where they're rendered within the Toggle
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ Elaborate on your learnings here in `src/exercise/04.md`
66
77## Background
88
9+ ** One liner:** The Prop Collections and Getters Pattern allows your hook to
10+ support common use cases for UI elements people build with your hook.
11+
912In typical UI components, you need to take accessibility into account. For a
1013button functioning as a toggle, it should have the ` aria-pressed ` attribute set
1114to ` true ` or ` false ` if it's toggled on or off. In addition to remembering that,
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ Elaborate on your learnings here in `src/exercise/05.md`
66
77## Background
88
9+ ** One liner:** The State Reducer Pattern inverts control over the state
10+ management of your hook and/or component to the developer using it so they can
11+ control the state changes that happen when dispatching events.
12+
913During the life of a reusable component which is used in many different
1014contexts, feature requests are made over and over again to handle different
1115cases and cater to different scenarios.
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ Elaborate on your learnings here in `src/exercise/06.md`
66
77## Background
88
9+ ** One liner:** The Control Props pattern allows users to completely control
10+ state values within your component. This differs from the state reducer pattern
11+ in the fact that you can not only change the state changes based on actions
12+ dispatched but you _ also_ can trigger state changes from outside the component
13+ or hook as well.
14+
915Sometimes, people want to be able to manage the internal state of our component
1016from the outside. The state reducer allows them to manage what state changes are
1117made when a state change happens, but sometimes people may want to make state
You can’t perform that action at this time.
0 commit comments