React · Exercise 1 of 6Next
Beginner
Your first hook: useToggle
Write a custom hook useToggle(initial = false) that keeps a true/false value in state and returns [on, toggle], where toggle flips the value.
Use it in Faq: the button (id="toggle") says Show answer when closed and Hide answer when open, and the answer paragraph (id="answer") appears only when open.
What Check tests
- There is a hook named
useTogglethat usesuseState - At the start the answer is hidden and the button says
Show answer - One click shows the answer and the button says
Hide answer - A second click hides it again
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.