We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 42cbca1 commit 62973c1Copy full SHA for 62973c1
src/auth-context.js
@@ -6,6 +6,7 @@ import React from 'react'
6
const AuthContext = React.createContext({
7
user: {username: 'jakiechan', tagline: '', bio: ''},
8
})
9
+AuthContext.displayName = 'AuthContext'
10
const AuthProvider = ({user, ...props}) => (
11
<AuthContext.Provider value={user} {...props} />
12
)
src/exercise/01.md
@@ -67,6 +67,18 @@ experiment a bit. It'll help your learning and retention to struggle with this.
67
- https://reactjs.org/docs/context.html
68
- https://reactjs.org/docs/hooks-reference.html#usecontext
69
70
+🦉 Tip: You may notice that the context provider/consumers in React DevTools
71
+just display as `Context.Provider` and `Context.Consumer`. That doesn't do a
72
+good job differentiating itself from other contexts that may be in your app.
73
+Luckily, you can set the context `displayName` and it'll display that name for
74
+the `Provider` and `Consumer`. Hopefully in the future this will happen
75
+automatically ([learn more](https://github.com/babel/babel/issues/11241)).
76
+
77
+```javascript
78
+const MyContext = React.createContext()
79
+MyContext.displayName = 'MyContext'
80
+```
81
82
## Extra Credit
83
84
### 💯 export hooks
src/exercise/02.md
@@ -35,6 +35,12 @@ it's selected? We can easily add API surface area to support these use cases,
35
but that's just more for us to code and more for users to learn. That's where
36
compound components come in really handy!
37
38
+Real World Components that implement Compound Components
39
40
+- [`@react/tooltip`](https://reacttraining.com/reach-ui/tooltip)
41
+- Actually most of [Reach UI](https://reacttraining.com/reach-ui) implements
42
+ this pattern
43
44
## Exercise
45
46
Every reusable component starts out as a simple implementation for a specific
src/final/01.extra-1.js
@@ -10,6 +10,7 @@ import * as userClient from '../user-client'
import {useAuth} from '../auth-context'
const UserContext = React.createContext()
13
+UserContext.displayName = 'UserContext'
14
15
function userReducer(state, action) {
16
switch (action.type) {
src/final/01.extra-2.js
@@ -10,7 +10,9 @@ import * as userClient from '../user-client'
const UserStateContext = React.createContext()
+UserStateContext.displayName = 'UserStateContext'
const UserDispatchContext = React.createContext()
+UserDispatchContext.displayName = 'UserDispatchContext'
17
18
src/final/01.extra-3.js
src/final/01.extra-4.js
src/final/01.js
@@ -9,6 +9,7 @@ import * as userClient from '../user-client'
src/final/03.extra-1.js
@@ -5,6 +5,7 @@ import React from 'react'
5
import {Switch} from '../switch'
const ToggleContext = React.createContext()
+ToggleContext.displayName = 'ToggleContext'
function Toggle({children}) {
const [on, setOn] = React.useState(false)
src/final/03.js
@@ -4,6 +4,7 @@ import React from 'react'
4
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments