Quiz: A Timer That Stands Still

The timer should count the seconds, but it shows 0 s all the time, and the console shows no error. Click the line with the mistake.

import { useEffect, useState } from "react";

export default function App() {
    const [seconds, setSeconds] = useState(0);

    useEffect(() => {
        const id = setInterval(() => {
            setSeconds((seconds) => seconds + 1);
        }, 1000);
        return clearInterval(id);
    }, []);

    return (
        <main>
            <h1>Summer Sounds</h1>
            <p className="timer">Night Trains on stage: {seconds} s</p>
        </main>
    );
}

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

Back

4/9

Next