Skip to content

Instantly share code, notes, and snippets.

@chimon2000
Created May 5, 2020 02:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chimon2000/5b145d5787dd0e4c3840b38612b34e6d to your computer and use it in GitHub Desktop.
Save chimon2000/5b145d5787dd0e4c3840b38612b34e6d to your computer and use it in GitHub Desktop.
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