React Dojo

Search

Search concepts, exercises and quizzes

practicebasic

Toggle button

A button that toggles between two states: 'off' and 'on'. Changes color and text based on state. Use the ternary operator for conditional rendering.


Objectives

  1. 1.Declare isOn state with initial value false
  2. 2.Display ON or OFF based on state
  3. 3.Change background color: green when on, gray when off
  4. 4.On click, toggle state with setIsOn(!isOn)
your code
Hint

The ternary operator: condition ? valueIfTrue : valueIfFalse

Related concepts

Was this helpful?
Sign in to give feedback