@modular-component/with-conditional-render 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +16 -8
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -13,20 +13,28 @@ Provides three stages that allow conditional rendering in `ModularComponent`s:
|
|
|
13
13
|
|
|
14
14
|
```tsx
|
|
15
15
|
import { ModularComponent } from '@modular-component/core'
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
condition,
|
|
18
|
+
conditionalFallback,
|
|
19
|
+
conditionalRender,
|
|
20
|
+
} from '@modular-component/with-conditional-render'
|
|
17
21
|
|
|
18
22
|
const ConditionalComponent = ModularComponent<{ enabled?: boolean }>()
|
|
19
23
|
.with(condition('disabled', ({ props }) => props.enabled !== true))
|
|
20
24
|
.with(conditionalFallback('disabled', () => <>I'm disabled!</>))
|
|
21
|
-
.with(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
.with(
|
|
26
|
+
lifecycle(() => {
|
|
27
|
+
// Some data fetching logic...
|
|
28
|
+
return { loading, data }
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
25
31
|
.with(condition('loading', ({ lifecycle }) => lifecycle.loading === false))
|
|
26
32
|
.with(conditionalFallback('loading', () => <>I'm loading!</>))
|
|
27
|
-
.with(
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
.with(
|
|
34
|
+
conditionalRender(({ lifecycle }) => (
|
|
35
|
+
<>I'm enabled and loaded, here is the content: {lifecycle.data}</>
|
|
36
|
+
)),
|
|
37
|
+
)
|
|
30
38
|
```
|
|
31
39
|
|
|
32
40
|
## Multiple conditions and fallbacks
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"Default",
|
|
9
9
|
"Conditional"
|
|
10
10
|
],
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.2",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"publishConfig": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"license": "cp ../../LICENSE ./LICENSE"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@modular-component/core": "0.2.
|
|
29
|
+
"@modular-component/core": "0.2.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">=17 <19"
|