Nested lists of components #436
Answered
by
sirenkovladd
denartha10
asked this question in
Q&A
-
Hi, I have a nested list of componets inside another componet but all I get rendered is I have put together a toy problem with the same issue and was hoping someone might be able to help me out with a solution that would render the components correctly const {div, h1, button} = van.tags
const ChildNode = ({color, text}) => div(
{
style: `background-color: ${color}; width: 50px; aspect-ratio: 1/1;`
},
h1(text)
)
const Parent = () => {
const nodes = van.state([])
return div(
{
id: 'random-sample-id',
style: 'height: 100vh; display: flex; flex-direction: column;'
},
button(
{
onclick: () => nodes.val = [ ...nodes.val, { color: '#e4e4e4', text: 'new' } ]
},
'ADD'
),
() => nodes.val.map(n => ChildNode({id: n.id, color: n.color, text: n.text}))
)
}
van.add(document.body, Parent()) |
Beta Was this translation helpful? Give feedback.
Answered by
sirenkovladd
Apr 16, 2025
Replies: 1 comment 2 replies
-
I think you need () => div(nodes.val.map(n => ChildNode({id: n.id, color: n.color, text: n.text})) also have a look at |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
denartha10
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you need
also have a look at
vanX.list
https://vanjs.org/x#reactive-list, it might help prevent rendering