Skip to content

Commit 18634d2

Browse files
committed
add one liners
Closes #76
1 parent 11101b8 commit 18634d2

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

src/exercise/01.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff 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+
913
Let'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+
)
100106
const value = {state, increment, decrement}
101107
return <CounterContext.Provider value={value} {...props} />
102108

src/exercise/02.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
913
Compound components are components that work together to form a complete UI. The
1014
classic example of this is `<select>` and `<option>` in HTML:
1115

src/exercise/03.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
913
Right now our component can only clone and pass props to immediate children. So
1014
we need some way for our compound components to implicitly accept the on state
1115
and toggle method regardless of where they're rendered within the Toggle

src/exercise/04.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
912
In typical UI components, you need to take accessibility into account. For a
1013
button functioning as a toggle, it should have the `aria-pressed` attribute set
1114
to `true` or `false` if it's toggled on or off. In addition to remembering that,

src/exercise/05.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
913
During the life of a reusable component which is used in many different
1014
contexts, feature requests are made over and over again to handle different
1115
cases and cater to different scenarios.

src/exercise/06.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
915
Sometimes, people want to be able to manage the internal state of our component
1016
from the outside. The state reducer allows them to manage what state changes are
1117
made when a state change happens, but sometimes people may want to make state

0 commit comments

Comments
 (0)