Skip to content

Fetch JSON into a list #458

Closed Answered by Tao-VanJS
shkhuz asked this question in Q&A
Jul 23, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

In VanJS, for state-derived child nodes, the binding function can't return an array of DOM nodes. They have to be encapsulated under a parent node - <ul> in your case. Sorry for the confusion. This is due to the limit of DOM API.

In the Counter example:

const Counter = () => {
  const counter = van.state(0)
  return span(
    "❤️ ", counter, " ",  // not wrapped in () =>
    button({onclick: () => ++counter.val}, "👍"),
    button({onclick: () => --counter.val}, "👎"),
  )
}

van.add(document.body, Counter())

counter can be considered as a syntax sugar for () => counter.val.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@shkhuz
Comment options

@Tao-VanJS
Comment options

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