From 0ea7a6303fa7d3cee9138824eca811009702523e Mon Sep 17 00:00:00 2001 From: David Leuliette Date: Thu, 17 Oct 2024 22:48:06 +0200 Subject: [PATCH 1/2] fix: add instructions for exercice 03.compound-components --- .../02.problem.validation/toggle.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exercises/03.compound-components/02.problem.validation/toggle.tsx b/exercises/03.compound-components/02.problem.validation/toggle.tsx index 978a30ee..eaefbd73 100644 --- a/exercises/03.compound-components/02.problem.validation/toggle.tsx +++ b/exercises/03.compound-components/02.problem.validation/toggle.tsx @@ -11,12 +11,19 @@ export function Toggle({ children }: { children: React.ReactNode }) { return {children} } +// 🐨 create a custom useToggle() hook here +// create a new context variable and read ToggleContext with use +// when no context is found, throw an error with usefull debugging information +// otherwise return the context + export function ToggleOn({ children }: { children: React.ReactNode }) { + // 🐨 instead reading context with use, we'll need to get that from useToggle() const { on } = use(ToggleContext)! return <>{on ? children : null} } export function ToggleOff({ children }: { children: React.ReactNode }) { + // 🐨 instead reading context with use, we'll need to get that from useToggle() const { on } = use(ToggleContext)! return <>{on ? null : children} } @@ -25,6 +32,7 @@ type ToggleButtonProps = Omit, 'on'> & { on?: boolean } export function ToggleButton({ ...props }: ToggleButtonProps) { + // 🐨 instead reading context with use, we'll need to get that from useToggle() const { on, toggle } = use(ToggleContext)! return } From d6f6b91e5b7898476dc0349451a89451d7697511 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Fri, 18 Oct 2024 08:05:21 +0530 Subject: [PATCH 2/2] Update exercises/03.compound-components/02.problem.validation/toggle.tsx --- .../03.compound-components/02.problem.validation/toggle.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/03.compound-components/02.problem.validation/toggle.tsx b/exercises/03.compound-components/02.problem.validation/toggle.tsx index eaefbd73..1b86f4d8 100644 --- a/exercises/03.compound-components/02.problem.validation/toggle.tsx +++ b/exercises/03.compound-components/02.problem.validation/toggle.tsx @@ -13,7 +13,7 @@ export function Toggle({ children }: { children: React.ReactNode }) { // 🐨 create a custom useToggle() hook here // create a new context variable and read ToggleContext with use -// when no context is found, throw an error with usefull debugging information +// when no context is found, throw an error with a useful message // otherwise return the context export function ToggleOn({ children }: { children: React.ReactNode }) {