Skip to content

How to use flutter_mobx with templates? #872

Answered by amondnet
gabrielguedest asked this question in Q&A
Discussion options

You must be logged in to vote

https://mobx.netlify.app/guides/when-does-mobx-react#3-beware-of-reading-values-instead-of-observables

This is just an extension of Rule 1. For MobX to do its job, you have to ensure only Observables are being read inside the reaction. If you happen to read the value instead of the observable, no tracking will take place. A simple example is shown below:

final count = Observable(10);
var value = count.value;

reaction((_) => value, (v) => print('New value: $v'));

Notice that we are reading the value inside the reaction's tracker-function. This is not an observable, but just a plain number. MobX will not do any tracking and effectively this reaction will never re-execute again!.

Observer(
…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by amondnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants