mr-wildcard
mr-wildcard

Reputation: 550

MobX: Update observable value in autorunAsync action

Sources here on develop branch.

In this simple app, I use autorunAsync to debounce searchText updates and fetch Giphy API accordingly. Everything works fine until I want to display a simple loader next to the input while a request is processing.

Uncommenting this line ends up with the action being fired infinitely.

enter image description here

I thought that autorun and autorunAsync would fire the action only when the targeted observable is modified. (searchText in my case)

How to combine both side effects (like API fetching) and state update within the same action ? I tried transaction, but I couldn't make it work either.. I need more time to wrap my head around MobX concept and I'm sure this is a stupid mistake. :)

Any help appreciated

Upvotes: 1

Views: 719

Answers (1)

mweststrate
mweststrate

Reputation: 4978

Your setup is correct. This was actually a bug in autorunAsync. MobX 2.0.2 should fix this issue.

Upvotes: 1

Related Questions