Programming Exercises

Create a React component that displays 'Welcome!' for 5 seconds and then changes to 'Goodbye!'.

Easy

Problem 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;
Log in or sign up to run or submit your code.Log inSign up
Expected Output
Initially: Welcome!
 After 5 seconds: Goodbye!