Create a component that renders a paragraph with a random color every time a button is clicked.
EasyProblem Statement
Create a component that renders a paragraph with a random color every time a button is clicked.
Sample Output
The paragraph text color changes to a random color when the button is clicked.
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 RandomColor = () => { const [color, setColor] = useState("black"); const changeColor = () => { // Generate and set a random color }; return ( <div> <p style={{ color }}>This is random color text.</p> <button onClick={changeColor}>Change Color</button> </div> ); }; export default RandomColor;