React
schematic-react is a client-side React library for Schematic which provides hooks to track events, check flags, and more. schematic-react provides the same capabilities as schematic-js, for React apps.
Install
Usage
SchematicProvider
You can use the SchematicProvider to wrap your application and provide the Schematic instance to all components:
Setting context
To set the user context for events and flag checks, you can use the identify function provided by the useSchematicEvents hook:
To learn more about identifying companies with the keys map, see key management in Schematic public docs.
Tracking usage
Once you’ve set the context with identify, you can track events:
If you want to record large numbers of the same event at once, or perhaps measure usage in terms of a unit like tokens or memory, you can optionally specify a quantity for your event:
Checking flags
To check a flag, you can use the useSchematicFlag hook:
Checking entitlements
You can check entitlements (i.e., company access to a feature) using a flag check as well, and using the useSchematicEntitlement hook you can get additional data to render various feature states:
Troubleshooting
For debugging and development, Schematic supports two special modes:
Debug Mode
Enables console logging of all Schematic operations:
Offline Mode
Prevents network requests and returns fallback values for all flag checks:
Offline mode automatically enables debug mode to help with troubleshooting.
License
MIT
Support
Need help? Please open a GitHub issue or reach out to support@schematichq.com and we’ll be happy to assist.
Next.js
If you’re building with Next.js, we recommend reading our Next.js SDK guide for more detailed recommendations on how implement Schematic in your Next.js application.