alanbuchanan alanbuchanan - 4 years ago 146
Javascript Question

`console.log` a mobx `@observable` whenever its value changes

Is there any way that a

will automatically fire whenever a mobx
changes value?

I would do it with mobx dev tools but it fires a huge amount of console logs so it's hard to pin point the property whose value I am tracking.

Answer Source

Yo can do:

import { autorun } from 'mobx';
autorun(() => {
  console.log(store.value); //value is an observable.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download