@schematichq/schematic-react 1.5.0 → 1.6.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 CHANGED
@@ -136,6 +136,35 @@ const MyComponent = () => {
136
136
 
137
137
  *Note: `useSchematicIsPending` is checking if entitlement data has been loaded, typically via `identify`. It should, therefore, be used to wrap flag and entitlement checks, but never the initial call to `identify`.*
138
138
 
139
+ For features metered by credit burndown, the same entitlement object carries the company's credit position:
140
+
141
+ | Property | Type | Description |
142
+ | --- | --- | --- |
143
+ | `creditId` | `string \| undefined` | The ID of the credit funding this feature |
144
+ | `creditSettled` | `number \| undefined` | The spendable balance, including any amount held by an open lease. This is the number to show end users |
145
+ | `creditRemaining` | `number \| undefined` | The balance available to fund new consumption, excluding any open lease hold |
146
+ | `creditReserved` | `number \| undefined` | The unspent amount held by an open credit lease, `0` when none is open |
147
+
148
+ All four are `undefined` when the feature is not credit-based.
149
+
150
+ ```tsx
151
+ import { useSchematicEntitlement } from "@schematichq/schematic-react";
152
+ import { Feature, OutOfCredits } from "./components";
153
+
154
+ const MyComponent = () => {
155
+ const { creditSettled, value: isFeatureEnabled } =
156
+ useSchematicEntitlement("my-flag-key");
157
+
158
+ if (!isFeatureEnabled) {
159
+ return <OutOfCredits />;
160
+ }
161
+
162
+ return <Feature creditsRemaining={creditSettled} />;
163
+ };
164
+ ```
165
+
166
+ These values refresh with each flag check. For a balance that also updates on the credit partials arriving between checks, pass `creditId` to [`useSchematicCreditBalance`](#credit-balances) instead.
167
+
139
168
  ### Company plan information
140
169
 
141
170
  To access the current company's plan and trial status, you can use the `useSchematicPlan` hook:
@@ -200,7 +229,22 @@ The hook returns an object with the following properties:
200
229
  | `balance` | `number` | The spendable balance, or `0` while loading or when the company holds no balance in this credit |
201
230
  | `isLoading` | `boolean` | `true` while the balance is still loading and no value has arrived yet |
202
231
 
203
- The credit ID is available on a feature's entitlement: `useSchematicEntitlement(key)` returns `creditId` for credit-based features.
232
+ The credit ID is available on a feature's entitlement, and the hook accepts `string | undefined`, so you can feed it straight through without waiting for the check to arrive:
233
+
234
+ ```tsx
235
+ const CreditMeter = () => {
236
+ const { creditId } = useSchematicEntitlement("my-flag-key");
237
+ const { balance, isLoading } = useSchematicCreditBalance(creditId);
238
+
239
+ if (isLoading) {
240
+ return <div>Loading…</div>;
241
+ }
242
+
243
+ return <div>{balance} credits remaining</div>;
244
+ };
245
+ ```
246
+
247
+ While `creditId` is `undefined`, the hook reports the client's loading state and a balance of `0`.
204
248
 
205
249
  ## Fallback Behavior
206
250
 
@@ -260,7 +304,7 @@ When events (track, identify) cannot be sent due to network issues, they are aut
260
304
 
261
305
  ### WebSocket Fallback
262
306
 
263
- In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as [outlined above](/#flag-check-fallbacks). The WebSocket will also automatically attempt to re-establish it's connection with Schematic using an exponential backoff.
307
+ In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as [outlined above](#flag-check-fallbacks). The WebSocket will also automatically attempt to re-establish its connection with Schematic using an exponential backoff.
264
308
 
265
309
  ## React Native
266
310