Using `querySelector*()` in a set reference function
From time to time I find the need to do something like this:
The issue with this code is that
element.querySelectorAll('[data-global-notification-close="true"]')
does not return any data because the children are not available at that time. if I use queueMicrotask()
like this:
While this seems to consistently work, using any type of async code like this always gives me a little fear that it will not work all the time.
Is this is a safe way to make sure querySelector*()
works or is there a better stable solution I should be done?1 Reply
Use it in
onMount
.
Then all elements are rendered