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 4bdcf46

Browse files
flexboxkentcdodds
andauthored
fix: add instructions for exercice 03.compound-components (#133)
* fix: add instructions for exercice 03.compound-components * Update exercises/03.compound-components/02.problem.validation/toggle.tsx --------- Co-authored-by: Kent C. Dodds <me@kentcdodds.com>
1 parent e8399be commit 4bdcf46

File tree

1 file changed

+8
-0
lines changed
  • exercises/03.compound-components/02.problem.validation

1 file changed

+8
-0
lines changed

‎exercises/03.compound-components/02.problem.validation/toggle.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ export function Toggle({ children }: { children: React.ReactNode }) {
1111
return <ToggleContext value={{ on, toggle }}>{children}</ToggleContext>
1212
}
1313

14+
// 🐨 create a custom useToggle() hook here
15+
// create a new context variable and read ToggleContext with use
16+
// when no context is found, throw an error with a useful message
17+
// otherwise return the context
18+
1419
export function ToggleOn({ children }: { children: React.ReactNode }) {
20+
// 🐨 instead reading context with use, we'll need to get that from useToggle()
1521
const { on } = use(ToggleContext)!
1622
return <>{on ? children : null}</>
1723
}
1824

1925
export function ToggleOff({ children }: { children: React.ReactNode }) {
26+
// 🐨 instead reading context with use, we'll need to get that from useToggle()
2027
const { on } = use(ToggleContext)!
2128
return <>{on ? null : children}</>
2229
}
@@ -25,6 +32,7 @@ type ToggleButtonProps = Omit<React.ComponentProps<typeof Switch>, 'on'> & {
2532
on?: boolean
2633
}
2734
export function ToggleButton({ ...props }: ToggleButtonProps) {
35+
// 🐨 instead reading context with use, we'll need to get that from useToggle()
2836
const { on, toggle } = use(ToggleContext)!
2937
return <Switch {...props} on={on} onClick={toggle} />
3038
}

0 commit comments

Comments
(0)

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