Mobx: Observable array does not display correctly

Viewed 22585

I am trying to understand how to use observable array with Mobx.

I have a hard time to figure out why this:

let entities = observable([]);
entities[0] = "foo";
autorun(() =>{
  console.log(entities);
});

writes:

[$mobx: Object]
0: (...)
1: (...)
2: (...)
3: (...)
4: (...)
5: (...)
6: (...)
7: (...)
8: (...)
9: (...)
10: (...)
11: (...)
12: (...)
13: (...)
14: (...)
15: (...)
16: (...)
17: (...)
...
999: (...)

Instead of a classic array?

2 Answers

Another way to log mobx observable is with toJS method

import { toJS } from 'mobx';

class Store {
  @observable
  fruits = ['Apple', 'Banana'];

  constructor() {
    console.log('this.views :', toJS(this.data));
  }
}

export default new Store();

Hope this help. Source

Related