-
Is it possible to do this in VanJS? Because so far, my efforts in this have failed. Sure, it is able to pass state with the exact initial value, but the reactive behaviour breaks down. |
Beta Was this translation helpful? Give feedback.
Answered by
bleistivt
Oct 24, 2024
Replies: 1 comment 3 replies
-
Lifting up shared state to the parent component works just like in other frameworks: const {button, div} = van.tags
const Child = ({count}) => div(
count,
" ",
button({onclick: () => count.val++}, "increment")
)
const Parent = () => {
const count = van.state(0)
return div(Child({count}), Child({count}))
}
van.add(document.body, Parent()) https://jsfiddle.net/j0wanotL/ Or do you want to do something else? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like this?
https://jsfiddle.net/gw6azf40/
Maybe I have misunderstood what you are trying to do. Do you have an example where the reactivity breaks down?