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
Log in to submit00:00
Try your code in this preview. Submit marks it done.
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;