@farmart-tech/brave-react-adapter
v3.0.1
Published
> React components and hooks for seamless Brave Ship feature flag integration.
Readme
@farmart-tech/brave-react-adapter
React components and hooks for seamless Brave Ship feature flag integration.
@farmart-tech/brave-react-adapter provides a set of React contexts and hooks to easily consume feature flags in any React application.
Features
- ⚛️ Hooks-first: Modern hooks like
useFeatureEnabledfor clean integration. - 🖼️ UI Components: Declarative
FeatureFlagGateandFeatureVariantcomponents. - 🛠️ Context Providers: Dedicated providers for both reading (client) and writing (admin) flags.
- 🔄 Real-time Updates: Automatically re-renders when feature flag configurations change in Firestore.
- ⚡ Persisted Startup Values: Reuses context-scoped, last-known evaluations on the first render while revalidating them in the background.
- 🧩 Type-Safe: Full TypeScript support for feature names and evaluation results.
Installation
npm install @farmart-tech/brave-react-adapter
# or
pnpm add @farmart-tech/brave-react-adapterPeer Dependencies
react>=18.0.0firebase^11.5.0@farmart-tech/brave-admin-sdk(provides core types)
Quick Start
1. Wrap your application
import { FeatureReaderProvider } from '@farmart-tech/brave-react-adapter';
import { getFirestore } from 'firebase/firestore';
const db = getFirestore(app);
function Root() {
return (
<FeatureReaderProvider
workspace="production"
db={db}
userContext={{ userId: 'user-123' }}
>
<App />
</FeatureReaderProvider>
);
}2. Use the hook
import { useFeatureEnabled } from '@farmart-tech/brave-react-adapter';
function Dashboard() {
const isEnabled = useFeatureEnabled('new_analytics_dashboard');
if (isEnabled === null) return <Loading />;
return isEnabled ? <NewDashboard /> : <StandardDashboard />;
}By default, resolved evaluations are stored in local storage for seven days. The cache key includes the workspace, environment, and user context, and every value is revalidated immediately. Applications that must fail closed on every startup can disable this behavior:
<FeatureReaderProvider
featureReaderConfig={config}
featureEvaluationCache={{ enabled: false }}
>
<App />
</FeatureReaderProvider>3. Use the Gate component
import { FeatureFlagGate } from '@farmart-tech/brave-react-adapter';
function ProfilePage() {
return (
<FeatureFlagGate
flag="edit_profile_v2"
fallback={<SimpleProfile />}
>
<AdvancedProfileEditor />
</FeatureFlagGate>
);
}Documentation
Comprehensive API documentation is available at: https://fmt-feature-management.web.app/docs/react-adapter/
License
MIT © FarMart
