lemmur-app-android/lib/hooks/stores.dart

24 lines
665 B
Dart
Raw Normal View History

import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
import 'package:mobx/mobx.dart';
2020-09-16 23:15:42 +02:00
import 'package:provider/provider.dart';
import '../stores/accounts_store.dart';
AccountsStore useAccountsStore() => useContext().watch<AccountsStore>();
2020-10-26 09:18:30 +01:00
T useAccountsStoreSelect<T>(T selector(AccountsStore store)) =>
useContext().select<AccountsStore, T>(selector);
V useStore<S extends Store, V>(V Function(S value) selector) {
final context = useContext();
final store = context.read<S>();
final state = useState(selector(store));
useEffect(() {
return autorun((_) {
state.value = selector(store);
});
}, []);
return state.value;
}