Skip to content

Sharing state between parent and child component? #378

Answered by bleistivt
Ashvith10 asked this question in Q&A
Discussion options

You must be logged in to vote

Like this?

const {button,div} = van.tags

const Child = ({onclick, text}) => button({onclick}, text)

const Parent = () => {
  const count = van.state(0)
  const onclick = () => count.val++
  return div(count, " ", Child({onclick, text: "increment"}))
}

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

https://jsfiddle.net/gw6azf40/

Maybe I have misunderstood what you are trying to do. Do you have an example where the reactivity breaks down?

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Ashvith10
Comment options

@bleistivt
Comment options

Answer selected by Ashvith10
@Ashvith10
Comment options

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