Create a React component that displays 'Welcome!' for 5 seconds and then changes to 'Goodbye!'.
EasyProblem Statement
Create a React component that displays 'Welcome!' for 5 seconds and then changes to 'Goodbye!'.
Sample Output
Initially: Welcome! After 5 seconds: Goodbye!
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, useEffect } from "react"; const TimedMessage = () => { const [message, setMessage] = useState("Welcome!"); useEffect(() => { // Change the message after 5 seconds }, []); return <div>{message}</div>; }; export default TimedMessage;