2021-10-31 12:52:58 +01:00
|
|
|
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);
|
|
|
|
|
2021-10-31 12:52:58 +01:00
|
|
|
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;
|
|
|
|
}
|