Passing Thoughts project, thoughts do not disappear

Hi everyone,
my thoughts won’t leave me! Maybe I should call a psychiatrist!!
The delete function works ok, when I click on the X they are deleted, but they do not disappear after 15 secs.

import React, { useEffect } from 'react';

export function Thought(props) {
  const { thought, removeThought } = props;

 useEffect(()=>{
    const timeRemaining = thought.expiresAt - Date.now();
    
    const timer = setTimeout(()=>{
      alert("Time passed");
    },timeRemaining)

    return ()=> {clearTimeout(timer)}
  },[thought]);

  const handleRemoveClick = () => {
    removeThought(thought.id);
  };

I tried also setting

const timeRemaining = 1000;

but it does not work either… :frowning:

The code shows the alert (of course the thought won’t disappear), but the alert is not showing either :frowning:

:laughing: hopefully a psychiatrist won’t be necessary, but the code snippet you provided does get a clean bill of health. I couldn’t spot any issues with it, so I even pasted it into my project and saw the alert.

You can try posting your full file and App.js if you’d like another set of eyes on it.

Hi thanks for the reply!
Well… actually when I reopened the app and clicked “save”, it all disappeared!
I was not able to detect any error in the code. So I reset the workspace, did the entire work once again, and finally it worked! Who knows…
thanks anyway! :slight_smile: