-
Hi, this is a very cool project! I was wondering if there is a unmount API that corresponds to Any answers would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @zidell, Thanks for reaching out! In VanJS, lifecycle event hooks can be easily implemented with the help of a lifecycle state and const stage = van.state("init")
van.add(document.body, () => {
if (stage.val === "init") return div()
if (stage.val === "mounted") return div(
<component content>
)
if (stage.val === "unmounted") return null
})
van.derive(() => {
if (stage.val === "mounted") {
<willmount hook>
} else if (stage.val === "unmounted") {
<willunmount hook>
}
}) The code can be slightly adjusted if you want hooks in more lifecycle stages. As a minimalist framework, VanJS won't include features that can be easily achieved with the combination of other features. Hope it helps :-) |
Beta Was this translation helpful? Give feedback.
Hi @zidell,
Thanks for reaching out!
In VanJS, lifecycle event hooks can be easily implemented with the help of a lifecycle state and
van.derive
. For example:The code can be slightly adjusted if you want hooks in more lifecycle stages.
As a minimalist framework, VanJS won't include features that can be easily achieved with t…