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
00:00
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;
Expected Output
Initially: Welcome! After 5 seconds: Goodbye!