Похожие чаты

Hello! I have a notification thingy that is removed automatically in

5 seconds, but if a new notification is triggered, I want this 5 seconds to start anew. I know how to do this in vanilla JS, but in React, for some reason, I had to use useRef(), for the name assigned to the timeOut not get lost between renders.

Is this how it should be done?

let timeoutID = useRef();

...
const sendMessage = (message, messageType, timeout = 5000) => {
clearTimeout(timeoutID.current);
...
timeoutID.current = setTimeout(() => dispatch(removeNotification()), timeout);
};

6 ответов

28 просмотров
Emre- Автор вопроса

Hello, a reminder for my simple react question

Unless we can reproduce the error on our end, it's a deadend. Set it in an online IDE such as Code Sandbox or repl.it to increase your chances, especially because the large majority of us is accessing Telegram from a mobile device.

Emre- Автор вопроса
Pedro Aguiar
Unless we can reproduce the error on our end, it's...

I don't have an error, it works as I want, I am asking whether using useRef here makes sense. But will provide the tools, thanks for your time

Emre
I don't have an error, it works as I want, I am as...

there's no "right" way in programming, it all depends on so many variables does it work? is it maintainable? is it testable? easy to change? scalable? for a throwaway project, as long as it works? for a project involving many devs, maybe testability is more important?

Fwiw you should not need a ref for it

Emre- Автор вопроса
david
Fwiw you should not need a ref for it

In the case of a state change I was losing the timeout ID so was not able to reset the timeout. This for sure did not feel natural, and probably was a result of a huuuge component that had many states in it

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта