K
K
KononovD2019-06-12 18:29:26
JavaScript
KononovD, 2019-06-12 18:29:26

How to perform some action after some time?

Yes, the essence of the question does not reflect my question, but it is indirectly related to it ...
The problem is the following: there is a "catalog" button, when you hover over it with the cursor, a directory with links drops out. This directory lies in the same div with the button, and the onMouseEnter event hangs on the div (the directory opens) and the onMouseMove event (the directory closes). I want to make it so that there would be some time after the cursor left the directory, before it was closed, and so that I could return the cursor back and nothing would be closed.
I'm doing this in react.
Somewhere I saw a similar system, timeouts and intervals were used there. like there was a condition in the interval and when the condition was true - the code inside was executed and a clearInterval was made. But I can't make friends with this scheme with React

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-06-12
@KononovD

onMouseLeave do this.timeout = setTimeout(callback, duration);
onMouseEnter doclearTimeout(this.timeout);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question