Event once rendering is complete #309
-
Is there anyway to listen for an event once rendering is done? Say, for example, that I have a I've tried using I'm sure that I could hack together a solution using the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
A quick and dirty solution is to use If you want to get rid of const {button, div} = van.tags
const Label = ({text, onRender}) => {
if (onRender) {
const trigger = van.state(false)
van.derive(() => trigger.val && onRender())
trigger.val = true
}
return div({class: "label"}, text)
}
const counter = van.state(0)
van.add(document.body,
div(button({onclick: () => ++counter.val}, "Increment")),
() => Label({
text: counter.val,
onRender: () => van.add(document.body,
div("Current label: ", document.querySelector(".label").innerText),
),
}),
) In this example, the Hope it helps :-) |
Beta Was this translation helpful? Give feedback.
-
You can also consider defining a custom element with |
Beta Was this translation helpful? Give feedback.
A quick and dirty solution is to use
setTimeout
with a smalldelay
. You can see this technique in a few places of the official codebase. For example: 1, 2. #123 is the thread that discusses the use ofsetTimeout
.If you want to get rid of
setTimeout
(thus the smalldelay
introduced by it). You can program your app in this way (this solution requires VanJS1.5.0
or later):