Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flutter Hook for StateNotifier
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:state_notifier/state_notifier.dart';
T useStateNotifier<T>(StateNotifier<T> notifier) {
final state = useState<T>(null);
useEffect(() {
return notifier.addListener((s) => state.value = s);
}, [notifier]);
return state.value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment