Does setTimeout functions remove after it worked?

Viewed 82

I want to add data on a div that comes from socket. And remove it after 5 seconds. (I am using socket.io client)

socket.on("data", (data) => {

    // add this data on div

    setTimeout(()=>{
      // remove data from div.
    }, 5000);

})

But a setTimeout function added each time a message arrives. May this a performance issue after some times? Should I remove it?

1 Answers

There's no need to worry about calling clearTimeout in your case. See this question.

If you are concerned about performance, here's a post about a promising alternative to setTimeout that could be helpful to you.

Related