Create a component that changes its text color to red when a button is clicked.
EasyProblem Statement
Create a component that changes its text color to red when a button is clicked.
Sample Output
Clicking the button changes the text color to red.
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
import React, { useState } from "react";
const ColorChanger = () => {
const [color, setColor] = useState("black");
const handleClick = () => {
// Change the state to set the color to red
};
return (
<div>
<p style={{ color }}>This text will change color.</p>
<button onClick={handleClick}>Change Color</button>
</div>
);
};
export default ColorChanger;
Expected Output
Clicking the button changes the text color to red.