Current Time 0:00
/
Duration Time 0:00
Progress: NaN%
Playback Rate
1.00x
Closed Caption

Flutter Hooks -- useState

Code

https://github.com/tinycasts/state_management/releases/tag/episode_01


About Flutter Hooks

Flutter Hooks was created by Remi Rousselet.

Hooks are a new kind of object that manages a Widget life-cycles. They exist for one reason: increase the code sharing between widgets and as a complete replacement for StatefulWidget. -- Remi Rousselet

In case you want to dive into knowing more about Hooks implementation (React), you can read this great article by Rudi Yardley, https://medium.com/@ryardley/react-hooks-not-magic-just-arrays-cd4f1857236e


Snippets

  1. Add Flutter Hooks to Pubspec
flutter_hooks: ^0.6.1
  1. Import the package
import 'package:flutter_hooks/flutter_hooks.dart';
  1. Add your state for counter
final counter = useState(0);
  1. Consume State
Text('${counter.value}')
  1. Change State
onPressed: () => counter.value++

Discuss

Loading comments...