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

Commit ccb614f

Browse files
committed
optimized AgileHOC doocs
1 parent a099e39 commit ccb614f

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

docs/packages/react/features/AgileHoc.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,54 @@ sidebar_label: AgileHOC
55
slug: /react/AgileHOC
66
---
77

8-
`AgileHOC` is a [Higher-Order Component](https://reactjs.org/docs/higher-order-components.html), that helps us to bind States to our React Component.
9-
108
:::info
119

12-
It is mainly thought for [Class Components](https://reactjs.org/docs/components-and-props.html),
13-
because for [Functional Components](https://reactjs.org/docs/components-and-props.html) we have create a much [neater solution](./Hooks.md), based on Hooks.
10+
The `AgileHOC` is mainly thought for [Class Components](https://reactjs.org/docs/components-and-props.html),
11+
as we recommend using Hooks in [Functional Components](https://reactjs.org/docs/components-and-props.html).
1412

1513
:::
1614

17-
The `AgileHOC` gets wrapped around our React Class Component, to
18-
ensure that our Class Component rerender, whenever a bound State mutates.
19-
The `output` of the passed States gets merged into the `props` of the Class Component.
20-
The property where the State Value is represented in the `props` is named after the State Key.
15+
The `AgileHOC` is a Higher Order Component that is wrapped around a React Component.
16+
It takes care of binding [Agile Sub Instances](../../../main/Introduction.md#agile-sub-instance) (like States or Collections) to the wrapped React Component.
2117
```tsx
2218
export default AgileHOC(RandomComponent, [MY_COOL_STATE]);
2319
```
24-
If our State has no key, be aware that you have to pass it in Object shape into the AgileHOC,
25-
so that it properly can be merged into the `props` of the Component.
20+
The `output` of the passed States will be mapped into the `props` property of the Class Component.
21+
Therefore, each State should have a unique key to be correctly represented by the `props` property.
22+
To be 100% sure that each State has its own key, we recommend providing the States to the `AgileHOC()` in a keymap instead of an array.
2623
```tsx
2724
export default AgileHOC(RandomComponent, {
28-
myState: MY_STATE
25+
myState: MY_STATE
2926
});
3027
```
31-
But it is recommended to use the direct State Value anyway, because it is more reliable and typesafe.
28+
However, using the direct State value is the most reliable and typesafe way.
3229
```tsx {4,9}
3330
class RandomComponent extends React.Component {
34-
render() {
35-
// return <h1>Hi {this.props.myCoolState}</h1>; // Not Typesafe
36-
return <h1>Hi {MY_COOL_STATE.value}</h1>; // Recommended | More Typesafe
37-
}
31+
render() {
32+
// return <h1>Hi {this.props.myCoolState}</h1>; // Not Typesafe
33+
return <h1>Hi {MY_COOL_STATE.value}</h1>; // Recommended | Typesafe
34+
}
3835
}
3936

40-
// Wrapping AgileHOC around our Component, and binding MY_COOL_STATE to it
37+
// Wrapping AgileHOC around the React Component and binding MY_COOL_STATE to it
4138
export default AgileHOC(RandomComponent, [MY_COOL_STATE]);
4239
```
43-
We are not limited to States, we can bind any [Agile Sub Instances](../../../main/Introduction.md#agile-sub-instance) that own
44-
an `observer` to a React Component.
40+
41+
### 🏷 Subscribable Instances
42+
We are not limited to States.
43+
We can bind any [Agile Sub Instance](../../../main/Introduction.md#agile-sub-instance) that owns
44+
an `Observer` to React Components.
4545
```ts
4646
export default AgileHOC(RandomComponent, [MY_COOL_STATE, MY_GROUP]);
4747
```
48-
[Agile Sub Instance](../../../main/Introduction.md#agile-sub-instance) with `observer`:
49-
- State
50-
- Group
51-
- Computed
52-
- Item
53-
- Collection (_exception_ since it has no `observer`)
54-
55-
56-
48+
Instances that can be bound to a React Component via the `useAgile()` Hook:
49+
- [`State`](../../core/features/state/Introduction.md)
50+
- [`Computed`](../../core/features/computed/Introduction.md)
51+
- [`Collection`](../../core/features/collection/Introduction.md)
52+
- [`Group`](../../core/features/collection/group/Introduction.md)
53+
- [`Selector`](../../core/features/collection/selector/Introduction.md)
54+
- [`Item`](../../core/features/collection/Introduction.md#-item)
55+
- `undefined`
5756

5857
### 🔴 Example
5958

@@ -69,7 +68,6 @@ class RandomComponent extends React.Component {
6968
<p>Props Value: {this.props.myFirstState}</p>
7069
<button
7170
onClick={() => {
72-
// Lets's update the State Value
7371
MY_STATE.set("Hello Friend!");
7472
}}
7573
>
@@ -88,17 +86,16 @@ render(<WrappedComponent/>);
8886
### 🟦 Typescript
8987

9088
The `AgileHOC` is nearly 100% typesafe.
91-
But the State Values that get merged into the `props` **aren't typesafe**.
92-
Because of that reason we recommend using the direct State Value (`MY_STATE.value`).
89+
But be aware that the [Agile Sub Instance](../../../main/Introduction.md#agile-sub-instance) `outputs` merged into the `props` property **aren't typesafe**.
9390

9491
### 📭 Props
9592

9693
| Prop | Type | Description | Required |
9794
| ----------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------|
98-
| `reactComponent` | ComponentClass | Component to which the passed Agile Sub Instances get applied | Yes |
99-
| `deps` | DepsType | Agile Sub Instances that get bound to the Component | Yes |
100-
| `key` | string \| number | Key/Name of Observer that gets created. Mainly thought for Debugging. | No |
101-
| `agileInstance` | Agile | To which Agile Instance the State get bound. Gets autodetect if only one Agile Instance exists. | No |
95+
| `reactComponent` | ComponentClass | Component to which the passed Agile Sub Instances will be applied | Yes |
96+
| `deps` | DepsType | Agile Sub Instances that are bound to the passed Component | Yes |
97+
| `key` | string \| number | Key/Name of SubscriptionContainer that is created. Mainly thought for Debugging | No |
98+
| `agileInstance` | Agile | To which Agile Instance the State belongs. Automatically detected if only one Agile Instance exists. | No |
10299

103100
#### DepsType
104101
```ts
@@ -115,4 +112,7 @@ type SubscribableAgileInstancesType = State | Collection | Observer | undefined;
115112

116113
### 📄 Return
117114

118-
`AgileHOC` returns a modified version of the React Component that got passed in.
115+
```ts
116+
AgileReactComponent
117+
```
118+
Returns a modified version of the passed React Component.

0 commit comments

Comments
 (0)