@schematichq/schematic-react 1.0.2 → 1.1.0
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/README.md +40 -1
- package/dist/schematic-react.cjs.js +394 -120
- package/dist/schematic-react.d.ts +11 -6
- package/dist/schematic-react.esm.js +392 -118
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -65,10 +65,11 @@ const MyComponent = () => {
|
|
|
65
65
|
};
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
To check a flag, you can use the `
|
|
68
|
+
To check a flag, you can use the `useSchematicFlag` hook:
|
|
69
69
|
|
|
70
70
|
```tsx
|
|
71
71
|
import { useSchematicFlag } from "@schematichq/schematic-react";
|
|
72
|
+
import { Feature, Fallback } from "./components";
|
|
72
73
|
|
|
73
74
|
const MyComponent = () => {
|
|
74
75
|
const isFeatureEnabled = useSchematicFlag("my-flag-key");
|
|
@@ -77,6 +78,44 @@ const MyComponent = () => {
|
|
|
77
78
|
};
|
|
78
79
|
```
|
|
79
80
|
|
|
81
|
+
For flags that are checking company access to a feature based on usage, you can render additional states using the `useSchematicFlagCheck` hook, e.g.:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import {
|
|
85
|
+
useSchematicFlagCheck,
|
|
86
|
+
useSchematicIsPending,
|
|
87
|
+
} from "@schematichq/schematic-react";
|
|
88
|
+
import { Feature, Loader, NoAccess } from "./components";
|
|
89
|
+
|
|
90
|
+
const MyComponent = () => {
|
|
91
|
+
const schematicIsPending = useSchematicIsPending();
|
|
92
|
+
const {
|
|
93
|
+
featureAllocation,
|
|
94
|
+
featureUsage,
|
|
95
|
+
featureUsageExceeded,
|
|
96
|
+
value: isFeatureEnabled,
|
|
97
|
+
} = useSchematicFlagCheck("my-flag-key");
|
|
98
|
+
|
|
99
|
+
// loading state
|
|
100
|
+
if (schematicIsPending) {
|
|
101
|
+
return <Loader />;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// usage exceeded state
|
|
105
|
+
if (featureUsageExceeded) {
|
|
106
|
+
return (
|
|
107
|
+
<div>
|
|
108
|
+
You have used all of your usage ({featureUsage} /{" "}
|
|
109
|
+
{featureAllocation})
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// either feature or "no access" state
|
|
115
|
+
return isFeatureEnabled ? <Feature /> : <NoAccess />;
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
80
119
|
## License
|
|
81
120
|
|
|
82
121
|
MIT
|