Programming Exercises

Build a component that toggles between light and dark themes with a button click.

Medium

Problem Statement

Build a component that toggles between light and dark themes with a button click.

Sample Input

Initial theme: 'light'

Sample Output

Background color switches between white and black.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React, { useState } from "react"; const ThemeToggler = () => { return ( <div> <button>Toggle Theme</button> </div> ); }; export default ThemeToggler;
Log in or sign up to run or submit your code.Log inSign up
Input
Initial theme: 'light'
Expected Output
Background color switches between white and black.