Created
May 5, 2020 02:59
-
-
Save chimon2000/5b145d5787dd0e4c3840b38612b34e6d to your computer and use it in GitHub Desktop.
Flutter Hook for StateNotifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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