Build a component that toggles between light and dark themes with a button click.
MediumProblem 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;
Input
Initial theme: 'light'
Expected Output
Background color switches between white and black.