You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The <HT>`ReactterSelector`</HT> widget is an similarly to <HT>[`ReactterConsumer`](/reactter/widgets/reactter_consumer)</HT>. It obtains the dependency provided by the closest <HT>[`ReactterProvider`](/reactter/widgets/reactter_provider)</HT> widget and allows you to select a specific value from the state to rebuild the widget tree when the value changes.
13
+
14
+
15
+
## Syntax
16
+
17
+
```dart showLineNumbers=false
18
+
ReactterSelector<T, V>({
19
+
Key? key,
20
+
String? id,
21
+
Widget? child,
22
+
required V selector(
23
+
T instance,
24
+
ReactterState select(ReactterState state),
25
+
),
26
+
required Widget builder(
27
+
BuildContext context,
28
+
T instance,
29
+
V value,
30
+
Widget? child,
31
+
),
32
+
})
33
+
```
34
+
35
+
## Properties
36
+
37
+
-`key`: An optional <HT>`Key`</HT> to use for identifying the widget.
38
+
-`id`: An optional <HT>`String`</HT> to identify the selector.
39
+
-`child`: An optional <HT>`Widget`</HT> which is independent of the <HT>`ReactterSelector`</HT>.
40
+
If defined, it is passed to the <HM>`builder`</HM> function.
41
+
- <HM>`selector`</HM>: A function that computes a value <HT>`V`</HT> from one or more states and listens for changes to rebuild the widget tree when the value changes.
42
+
It receives the following arguments:
43
+
-`instance`: The instance of <HT>`T`</HT> dependency provided by the closest <HT>`ReactterProvider`</HT> widget.
44
+
-`select`: A function that allows you to wrap the state to be listened for changes and returns it.
45
+
- <HM>`builder`</HM>: A function that builds a widget depending on the <HT>`ReactterSelector`</HT>.
46
+
It receives the following arguments:
47
+
-`context`: The <HT>`BuildContext`</HT> of the widget. A handle to the location of <HT>`ReactterSelector`</HT> in the widget tree.
48
+
-`instance`: The instance of <HT>`T`</HT> dependency provided by the closest <HT>`ReactterProvider`</HT> widget.
49
+
-`value`: The selected value computed <HT>`V`</HT> by the <HM>`selector`</HM> function.
50
+
-`child`: The `child` widget passed to the <HT>`ReactterSelector`</HT> widget.
51
+
52
+
53
+
## Usage
54
+
55
+
### Basic Usage
56
+
57
+
In the following example, we have a simple counter application that uses the <HT>`ReactterSelector`</HT> widget to select a specific value from the state to rebuild the widget tree when the value changes.
0 commit comments