Deviopath › React

Custom Hook: useToggle

Medium · Custom Hooks

The Lamp and Spoiler components are already written, but they use a custom hook that does not exist yet.

Write useToggle(initialValue). It returns an array [value, toggle]: value starts as initialValue, and calling toggle() flips it between true and false.

Each component that calls the hook gets its own independent state.

Next: useCounter Hook