Skip to content
Rung

03/12

No. 03Easy12 min

Conditional Rendering: The Traffic Light

Mission

Show different UI depending on state, using clean techniques: a lookup object, ternaries and the && shortcut.

Tasks

  1. 1

    Create a state called status, initialised to 'loading'.

  2. 2

    Define a config object outside the return that maps each status (success, error, loading) to a color, an icon and a message.

  3. 3

    Make the container's background use the color of the current status.

  4. 4

    Render the icon and the message by reading from your config object.

  5. 5

    Wire the three buttons so each one sets the matching status.