Feature flags
Pass visitor data into your docs through a feature flag provider
LaunchDarkly
1
2
3
npm install @gitbook/adaptive4
import { render } from 'react-dom';
import { withLaunchDarkly } from '@gitbook/adaptive';
import { asyncWithLDProvider, useLDClient } from 'launchdarkly-react-client-sdk';
import MyApplication from './MyApplication';
function PassFeatureFlagsToGitBookSite() {
const ldClient = useLDClient();
React.useEffect(() => {
if (!ldClient) {
return;
}
return withLaunchDarkly(ldClient);
}, [ldClient]);
return null;
}
(async () => {
const LDProvider = await asyncWithLDProvider({
clientSideID: 'client-side-id-123abc',
context: {
kind: 'user',
key: 'user-key-123abc',
name: 'Sandy Smith',
email: 'sandy@example.com'
},
options: { /* ... */ }
});
render(
<LDProvider>
<PassFeatureFlagsToGitBookSite />
<MyApplication />
</LDProvider>,
document.getElementById('reactDiv'),
);
})();5
6
Reflag
1
2
3
npm install @gitbook/adaptive4
import { withReflag } from '@gitbook/adaptive';
import { ReflagProvider, useClient } from '@reflag/react-sdk';
import MyApplication from './MyApplication';
function PassFeatureFlagsToGitBookSite() {
const client = useClient();
React.useEffect(() => {
if (!client) {
return;
}
return withReflag(client);
}, [client]);
return null;
}
export function Application() {
const currentUser = useLoggedInUser();
const appConfig = useAppConfig();
return (
<ReflagProvider
publishableKey={appConfig.reflagCom.publishableKey}
user={{
id: currentUser.uid,
email: currentUser.email ?? undefined,
name: currentUser.displayName ?? '',
}}
company={{
id: currentUser.company.id,
}}
>
<PassFeatureFlagsToGitBookSite />
<MyApplication />
</ReflagProvider>
);
}5
6
Last updated
Was this helpful?