Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 057efe4

Browse files
committed
fixed typos
1 parent b19a502 commit 057efe4

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

docs/packages/react/api/Hooks.md

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ slug: /react/hooks
1414

1515
## `useAgile()`
1616

17-
The `useAgile()` React Hook binds/subscribes States to Functional React Components.
17+
The `useAgile()` React Hook binds/subscribes AgileTs States to Functional React Components for reactivity.
1818
This binding ensures that the Component re-renders whenever a bound State changes.
1919
We can flexibly bind any [Agile Sub Instances](../../../main/Introduction.md#agile-sub-instance)
2020
(like States or Collections) to any React Component.
2121
```ts
22-
const myCoolState = useAgile(MY_COOL_STATE);
22+
const myCoolState = useAgile(MY_COOL_STATE);
2323
```
24-
The `useAgile()` Hook returns the current `value` of the provided State Instance
24+
The `useAgile()` Hook returns the current `value` of the provided State
2525
and **not** the State Instance itself.
2626
```ts {5}
2727
// -- core.js --------------------------------------------------
@@ -36,7 +36,7 @@ console.log(myState); // Returns 'jeff'
3636

3737
### 📚 Array
3838

39-
We can also pass an array of State Instances into the `useAgile()` Hook.
39+
We can also pass an array of States to the `useAgile()` Hook.
4040
```ts
4141
useAgile([MY_COOL_STATE1, MY_COOL_STATE2]);
4242
```
@@ -59,14 +59,14 @@ It can reduce the number of triggered re-render events by batching re-render job
5959
Thereby, simultaneously triggered re-render events of different State Instances
6060
are combined into one single (combined) re-render event
6161
if these States share the same `SubscriptionContainer`.
62-
Each `useAgile()` Hook creates its own `Subscription Container` and registers it by AgileTs.
63-
`Subscription Container` serve as an interface to the React-Component for AgileTs.
62+
Each `useAgile()` Hook creates its own `Subscription Container` and registers it with AgileTs.
63+
Simply put `Subscription Container` serve as an interface to React-Components for AgileTs.
6464

6565
### 👀 Subscribable Instances
6666

6767
Not only AgileTs States can be bound to React Components,
6868
but also all [Agile Sub Instances](../../../main/Introduction.md#agile-sub-instance)
69-
that contain an `Observer`.
69+
that contain an [`Observer`](../../../main/Introduction.md#observer).
7070
```ts
7171
const [myCollection, myGroup, myState] = useAgile([MY_COLLECTION, MY_GROUP, MY_STATE]);
7272
```
@@ -94,9 +94,10 @@ Instances that contain an `Observer` are, for example:
9494
console.log(myComputed); // Returns 'hello there'
9595
```
9696
- ### [`Collection`](../../core/api/collection/Introduction.md)
97-
**Note:** The Collection has no own `Observer`.
97+
**Note:** A Collection doesn't contain directly an `Observer`.
9898
But `useAgile()` is smart enough, to identify a Collection
99-
and binds the [`defualt` Group](../../core/api/collection/group/Introduction.md#-default-group) to the Component instead.
99+
and binds the [`defualt` Group](../../core/api/collection/group/Introduction.md#-default-group)
100+
to the React Component instead.
100101
The `default` Group represents the default pattern of the Collection.
101102
```ts {9}
102103
// -- core.js --------------------------------------------------
@@ -160,7 +161,7 @@ Instances that contain an `Observer` are, for example:
160161
const MY_STATE = createState("Hello Stranger!");
161162

162163
const RandomComponent = () => {
163-
const myFirstState = useAgile(MY_STATE); // Returns "Hello Stranger!"
164+
const myFirstState = useAgile(MY_STATE);
164165

165166
return (
166167
<div>
@@ -199,7 +200,7 @@ console.log(typeof stringState); // Returns 'string'
199200

200201
| Prop | Type | Description | Required |
201202
| ----------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------|
202-
| `deps` | Array<SubscribableAgileInstancesType\> \| SubscribableAgileInstancesType | Agile Sub Instances that are bound to the Component in which the useAgile Hook is located | Yes |
203+
| `deps` | Array<SubscribableAgileInstancesType\> \| SubscribableAgileInstancesType | Agile Instances to be bound to the Functional Component. | Yes |
203204
| `config` | [AgileHookConfigInterface](../../../Interfaces.md#agilehookconfiginterface) | Configuration | No |
204205

205206
#### SubscribableAgileInstancesType
@@ -209,21 +210,23 @@ type SubscribableAgileInstancesType = State | Collection | Observer | undefined;
209210

210211
### 📄 Return
211212

212-
`useAgile()` returns the current `output` of the specified [Agile Sub Instance](../../../main/Introduction.md#agile-sub-instance).
213+
The `useAgile()` Hook returns the current `output`
214+
of the specified [Agile Sub Instance](../../../main/Introduction.md#agile-sub-instance).
213215
```ts {5}
214-
const MY_STATE = App.createState('jeff');
216+
const MY_STATE = createState('jeff');
215217

216218
// -- MyComponent.jsx ------------------------------------------
217219

218220
const myState = useAgile(MY_STATE);
219221
console.log(myState); // Returns 'jeff'
220222
```
221-
When passing multiple Agile Sub Instances, an array of `outputs` matching the passed Instances is returned.
223+
When passing multiple Agile Sub Instances,
224+
an array of `outputs` matching the passed Instances is returned.
222225
```ts {6}
223226
// -- core.js --------------------------------------------------
224227

225-
const MY_STATE = App.createState('jeff');
226-
const MY_STATE_2 = App.createState('frank');
228+
const MY_STATE = createState('jeff');
229+
const MY_STATE_2 = createState('frank');
227230

228231
// -- MyComponent.jsx ------------------------------------------
229232

@@ -244,29 +247,35 @@ console.log(myState2); // Returns 'frank'
244247

245248
## `useProxy()`
246249

250+
:::warning
251+
252+
Requires an additional package called `@agile-ts/proxytree`!
253+
254+
:::
255+
247256
The `useProxy()` is in its basic functionality equivalent to the [`useAgile()`](#useagile) Hook.
248257
It binds/subscribes AgileTs States to Functional React Components for reactivity.
249-
However, it has one advantage in terms of performance
250-
by only re-rendering the Component when an actual accessed property changes.
258+
However, it has one advantage in terms of performance.
259+
Because it only re-renders the React Component when an actual accessed property changes.
251260
This is accomplished by warping a [Proxy()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
252261
around the returned State value/s.
253-
Through these Proxy, AgileTs is able to exactly track accessed properties in the returned State value object/s
254-
and construct paths to these.
262+
Through this Proxy, AgileTs is able to exactly track accessed properties in the React Component
263+
and can construct paths to these. Based on these paths, it can select the particular accessed properties.
255264

256-
Using the `useAgile()`, the Component would be always re-rendered on a subscribed State value change,
257-
regardless of whether the changed property value was accessed in the Component.
265+
With the `useAgile()` the Component would always be re-rendered on a subscribed State value change,
266+
regardless of whether the changed property value was accessed in the Component or not.
258267

259268
### 👀 Subscribable Instances
260269

261270
Not only AgileTs States can be bound to React Components,
262271
but also all [Agile Sub Instances](../../../main/Introduction.md#agile-sub-instance)
263-
that contain an `Observer`.
272+
that contain an [`Observer`](../../../main/Introduction.md#observer).
264273
```ts
265274
const [myCollection, myGroup, myState] = useProxy([MY_COLLECTION, MY_GROUP, MY_STATE]);
266275
```
267276
However, a [Javascript Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
268-
can only be wrapped around values of the type object.
269-
Other provided instances are treated as in [`useAgile()`](#useagile).
277+
can only be wrapped around values of the type `object`.
278+
Instances that are not of the type object are treated as in [`useAgile()`](#useagile).
270279

271280
### 🔴 Example
272281

@@ -285,7 +294,7 @@ const RandomComponent = () => {
285294
<div>
286295
<p>Name: {myState.name}</p>
287296
<p>Rerender: {rerenderCount}</p>
288-
<p>State Value: {JSON.stringify(MY_STATE.value)}</p>
297+
<p>State Value (not subscribed): <br/> {JSON.stringify(MY_STATE.value)}</p>
289298
<button
290299
onClick={() => {
291300
MY_STATE.patch({name: generateId()})

0 commit comments

Comments
 (0)