Build a useToggle Hook
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write a custom hook and export it by name: useToggle(initial) keeps a true or false value that starts at initial (false when it's left out) and returns an array [value, toggle]. Calling toggle flips the value. toggle ignores any argument it's given, so it can be passed straight to onClick. Each component that calls useToggle keeps its own value. The default export App uses it to show and hide an answer in the preview; the checks test useToggle itself.
Your code must pass
- Starts at the initial value, false by default
- toggle flips the value, even when passed an event
- Each component keeps its own value