The second argument to autorun() is an object that carries the options:
autorun(() => { /* side effects */}, options)
It has the following properties:
- name: This is useful for debugging purposes, especially in the context of MobX DevTools, where the name is printed in the logs. The name is also used with the spy() utility function provided by MobX. Both of these will be covered in a later chapter.
- delay: This acts as a debouncer for frequently changing observables. The effect-function will wait for the delay period (specified in milliseconds) before re-executing. In the example shown next, we want to be careful not to fire a network request for every change to profile.couponsUsed. An easy guard is to use the delay