File tree 1 file changed +8
-0
lines changed
exercises/03.compound-components/02.problem.validation
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,19 @@ export function Toggle({ children }: { children: React.ReactNode }) {
11
11
return < ToggleContext value = { { on, toggle } } > { children } </ ToggleContext >
12
12
}
13
13
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
+
14
19
export function ToggleOn ( { children } : { children : React . ReactNode } ) {
20
+ // 🐨 instead reading context with use, we'll need to get that from useToggle()
15
21
const { on } = use ( ToggleContext ) !
16
22
return < > { on ? children : null } </ >
17
23
}
18
24
19
25
export function ToggleOff ( { children } : { children : React . ReactNode } ) {
26
+ // 🐨 instead reading context with use, we'll need to get that from useToggle()
20
27
const { on } = use ( ToggleContext ) !
21
28
return < > { on ? null : children } </ >
22
29
}
@@ -25,6 +32,7 @@ type ToggleButtonProps = Omit<React.ComponentProps<typeof Switch>, 'on'> & {
25
32
on ?: boolean
26
33
}
27
34
export function ToggleButton ( { ...props } : ToggleButtonProps ) {
35
+ // 🐨 instead reading context with use, we'll need to get that from useToggle()
28
36
const { on, toggle } = use ( ToggleContext ) !
29
37
return < Switch { ...props } on = { on } onClick = { toggle } />
30
38
}
You can’t perform that action at this time.
0 commit comments