Back

React Exercises / Toggle State Hook

00:00
1/20

Toggle State Hook

Easy

Write a custom hook useToggle(initialValue) that returns a boolean state and a function to toggle it.

  • 1

    Use useState.

  • 2

    Define a function that calls setValue(!value).

  • 3

    Return the pair as an array.

JAVASCRIPT PLAYGROUND
JAVASCRIPT PLAYGROUND
⏳ Loading editor…