@@ -36,7 +36,7 @@ console.log(myState); // Returns 'jeff'
36
36
``` ts
37
37
const [myCoolState1, myCoolState2] = useAgile ([MY_COOL_STATE1 , MY_COOL_STATE2 ]);
38
38
```
39
- Now it returns an array of State ` values ` that can be destructured.
39
+ In which case it returns an array of State ` values ` that can be destructured.
40
40
``` ts {6}
41
41
const MY_STATE = App .createState (' jeff' );
42
42
const MY_STATE_2 = App .createState (' frank' );
@@ -47,9 +47,9 @@ const [myState, myState2] = useAgile([MY_STATE, MY_STATE_2]);
47
47
console .log (myState ); // Returns 'jeff'
48
48
console .log (myState2 ); // Returns 'frank'
49
49
```
50
- Binding multiple States to a Component in a single ` useAgile() ` Hook has one advantage.
51
- In some cases, it can lower the rerender count of the React Component.
52
- This is due to the fact that simultaneously triggered rerender of different States can be combined into one single rerender
50
+ Binding multiple States to a Component using a single ` useAgile() ` Hook has one advantage.
51
+ In some cases, it can reduce the rerender count of the React Component triggered by AgileTs .
52
+ This is due to the fact that simultaneously triggered rerenders of different States are combined into one single rerender
53
53
if the States share the same ` SubscriptionContainer ` .
54
54
Each ` useAgile() ` Hook creates its own ` SubscriptionContainer ` ,
55
55
which serves as an interface to the Component in order to trigger rerender on it.
@@ -81,8 +81,8 @@ Instances that can be bound to a React Component via the `useAgile()` Hook:
81
81
console .log (myComputed ); // Returns 'hello there'
82
82
```
83
83
- ### [ ` Collection ` ] ( ../../core/features/collection/Introduction.md )
84
- ** Note:** The Collection has no own ` observer ` .
85
- But ` useAgile() ` is smart enough, to identify a Collection under the hood
84
+ ** Note:** The Collection has no own ` Observer ` .
85
+ But ` useAgile() ` is smart enough, to identify a Collection
86
86
and binds the [ ` defualt ` Group] ( ../../core/features/collection/group/Introduction.md#-default-group ) to the Component instead.
87
87
The ` default ` Group represents the default pattern of the Collection.
88
88
``` ts {7}
@@ -184,16 +184,24 @@ type SubscribableAgileInstancesType = State | Collection | Observer | undefined;
184
184
### 📄 Return
185
185
186
186
` useAgile() ` returns the current ` output ` of the passed [ Agile Sub Instance] ( ../../../main/Introduction.md#agile-sub-instance ) .
187
- ``` ts {6,9 }
188
- const MY_STATE = App .State ( 1 );
189
- const MY_STATE_2 = App . State ( 2 );
190
- const MY_STATE_3 = App . State ( 3 );
187
+ ``` ts {5 }
188
+ const MY_STATE = App .createState ( ' jeff ' );
189
+
190
+ // myComponent.jsx
191
191
192
- // One passed Agile Sub Instance
193
- useAgile (MY_STATE ); // Returns 3
192
+ const myState = useAgile (MY_STATE );
193
+ console .log (myState ); // Returns 'jeff'
194
+ ```
195
+ When passing multiple Agile Sub Instances, an array of ` outputs ` matching the passed Instances is returned.
196
+ ``` ts {6}
197
+ const MY_STATE = App .createState (' jeff' );
198
+ const MY_STATE_2 = App .createState (' frank' );
199
+
200
+ // myComponent.jsx
194
201
195
- // Multiple passed Agile Sub Instances
196
- useAgile ([MY_STATE , MY_STATE_2 , MY_STATE_3 ]); // Returns [1, 2, 3]
202
+ const [myState, myState2] = useAgile ([MY_STATE , MY_STATE_2 ]);
203
+ console .log (myState ); // Returns 'jeff'
204
+ console .log (myState2 ); // Returns 'frank'
197
205
```
198
206
199
207
@@ -207,17 +215,17 @@ useAgile([MY_STATE, MY_STATE_2, MY_STATE_3]); // Returns [1, 2, 3]
207
215
208
216
209
217
## ` useWatcher() `
210
- A ` callback ` that observes the State on changes.
218
+ Creates a ` callback ` that observes the State on changes.
211
219
The provided ` callback ` function will be fired on every State ` value ` mutation.
212
220
For instance if we update the State value from 'jeff' to 'hans'.
213
221
``` ts
214
- useWatcher (MY_STATE , (value , key ) => {
222
+ useWatcher (MY_STATE , (value ) => {
215
223
console .log (value ); // Returns current State Value
216
- console .log (key ); // Key of Watcher ("Aj2pB")
217
224
});
218
225
```
219
226
It is a synonym to the [ ` watch() ` ] ( ../../core/features/state/Methods.md#watch ) method.
220
- But it has some advantages. It automatically cleans up the created watcher callback when the React Component unmounts
227
+ However, it has some advantages.
228
+ For example, it automatically cleans up the created watcher callback when the React Component unmounts
221
229
and might be cleaner to read in 'UI-Component-Code'.
222
230
223
231
### 🔴 Example
0 commit comments