Skip to content
Discussion options

You must be logged in to vote

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:

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 t…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@Tao-VanJS
Comment options

@zidell
Comment options

@Tao-VanJS
Comment options

@Tao-VanJS
Comment options

@Tao-VanJS
Comment options

Answer selected by Tao-VanJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants