@schematichq/schematic-react 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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 `useSchematicFlags` hook:
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