Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 806e260

Browse files
RuffengRuben Suet
authored and
Kent C. Dodds
committed
Fix 02 solution / Tip for 03 exercise (#8)
* Fix 02 solution / Tip for 03 exercise * Fix typo Co-authored-by: Ruben Suet <ruben.suet@xing.com>
1 parent 88c2ae2 commit 806e260

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

‎src/exercises-final/02.extra-1.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Toggle({children}) {
88
const [on, setOn] = React.useState(false)
99
const toggle = () => setOn(!on)
1010
return React.Children.map(children, child => {
11-
return typeof child === 'string'
11+
return typeof child.type === 'string'
1212
? child
1313
: React.cloneElement(child, {on, toggle})
1414
})

‎src/exercises/01.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function UserProvider({children}) {
3030
// which retrieves the context value via React.useContext, then people can use
3131
// your custom hook. If you want to try that, then go ahead and put it here.
3232

33-
// This is a utility function which accepts the reduer's dispatch function
33+
// This is a utility function which accepts the reducer's dispatch function
3434
// as well as the user and any updates. It's responsible for interacting with
3535
// the userClient and the dispatch.
3636
async function updateUser(dispatch, user, updates) {

‎src/exercises/03.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ function Toggle({onToggle, children}) {
2222
// 🐨 we'll still get the children from props (as it's passed to us by the
2323
// developers using our component), but we'll get `on` implicitely from
2424
// ToggleContext now
25+
// 🦉 You can create a helper method to retrieve the context here. Thanks to that,
26+
// your context won't be exposed to the user
2527
// 💰 `const context = useContext(ToggleContext)`
2628
// 📜 https://reactjs.org/docs/hooks-reference.html#usecontext
2729
function ToggleOn({on, children}) {
2830
return on ? children : null
2931
}
3032

31-
// 🐨 do the same thing to this that you did to the On component
33+
// 🐨 do the same thing to this that you did to the ToggleOn component
3234
function ToggleOff({on, children}) {
3335
return on ? null : children
3436
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /