Skip to content

Not clear how to use state API with an object #17

Answered by artydev
brandonros asked this question in Q&A
Discussion options

You must be logged in to vote

But try to follow Tao advise :-)

const { button, span } = van.tags

class Counter {
  constructor() {
    this.state = {
      amount: van.state(0)
    }
  }

  onIncrementButtonClickFactory(self) {
    return (event) => {
      console.log(event)
      self.state.amount.val += 1
    }
  }

  onDecrementButtonClickFactory(self) {
    return (event) => {
      console.log(event)
      self.state.amount.val -= 1
    }
  }

  render() {
    const incrementButtonOnClick = this.onIncrementButtonClickFactory(this)
    const derementButtonOnClick = this.onDecrementButtonClickFactory(this)
    const incrementButton = button({ onclick: incrementButtonOnClick }, "👍")
    const decrementButton = button

Replies: 1 comment 8 replies

Comment options

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

@artydev
Comment options

@brandonros
Comment options

@artydev
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