Skip to content Skip to sidebar Skip to footer

Mobx Observable Array Not Updated

I am declaring a observable array in the following way in reactjs using mobx @observable cacheditems constructor() { this.cacheditems = [] Now I am retrieving the data fro

Solution 1:

When you do this.cacheditems = items you are overwriting the reference to the observable array. You can use replace instead:

class Store {
  @observable cacheditems = []

  constructor() {
    db.allDocs({include_docs: true}, (err, docs) => {
      var items = []
      docs.rows.map((obj, id) => {
        items.push(obj.doc)
      })
      this.cacheditems.replace(items)
    })
  }
}

Post a Comment for "Mobx Observable Array Not Updated"