Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  137] [ 1]  / answers: 1 / hits: 8562  / 2 Years ago, tue, june 21, 2022, 12:00:00

Vue has this nextTick function, which is an async function that waits until the DOM is flushed. This is particularly useful when you want to perform some operation directly upon an element, like scrolling a DIV with scroll(). This avoids the need to wrap this call into a blind setTimeout().


In React I resorted to setTimeout() in the past. Is there an equivalent to nextTick(), or any better way to do it?


More From » reactjs

 Answers
5

In this case it's possible to use setTimeout to achieve this goal.


See: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#late_timeouts


Because it will execute function given in parameter in the end of the current thread, it's close to the behaviour of Vue.nextTick.


Example : https://codesandbox.io/s/gallant-roman-y0b9un?file=/src/App.js


[#86] Friday, May 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennie

Total Points: 593
Total Questions: 102
Total Answers: 106

Location: Federated States of Micronesia
Member since Fri, Sep 16, 2022
2 Years ago
jennie questions
;