Skip to content

Commit cf742eb

Browse files
committed
Add tip box showing how watch() can replace watchIt() and watchValue()
1 parent d641c61 commit cf742eb

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎docs/documentation/watch_it/more_watch_functions.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ When your registered object IS a `Listenable`, use `watchIt()`:
2424
- You already have a reference to the `Listenable`
2525
- Most generic case
2626

27+
::: tip watch() is the Foundation
28+
`watch()` is the most flexible function - you can use it to replace `watchIt()` and `watchValue()`:
29+
30+
```dart
31+
// These are equivalent:
32+
final manager = watchIt<CounterManager>();
33+
final manager = watch(di<CounterManager>());
34+
35+
// These are equivalent:
36+
final count = watchValue((CounterManager m) => m.count);
37+
final count = watch(di<CounterManager>().count);
38+
```
39+
40+
**Why use the convenience functions?**
41+
- `watchIt()` is cleaner for getting the whole object from get_it
42+
- `watchValue()` provides better type inference and cleaner syntax
43+
- Both are just shortcuts that use `watch()` internally
44+
:::
45+
2746
## watchPropertyValue - Selective Updates
2847

2948
Only rebuild when a specific property changes:

0 commit comments

Comments
 (0)