Can action be asynchronous and return some value? So i can call action somewhere in my code and wait for it to finish and then do something else.
action:
@action
Future updateClubs() async {
var clubs = await ClubService.getClubs(userId,token);
listOfClubs = clubs;
return listOfClubs;
}
and then call it somewhere in my code:
var x = await store.updateClubs();
then do something else...
On await it says "The await expression can only be used in an asynchronous function.".
Am i missing something? Im new to concept of mobx :)
It's definitely possible. You can see it being used in here.
In your case, make it more type-safe by changing your return type to Future<List<Club>> or something along those lines.
BTW, its good to go through the examples source code. Many of the typical use cases have been covered there.
Most helpful comment
It's definitely possible. You can see it being used in here.
In your case, make it more type-safe by changing your return type to
Future<List<Club>>or something along those lines.BTW, its good to go through the examples source code. Many of the typical use cases have been covered there.