@featbit/react-client-sdk
Version:
FeatBit client SDK for React
39 lines (38 loc) • 1.97 kB
TypeScript
import React, { Component, PropsWithChildren } from "react";
import { EnhancedComponent, ProviderConfig, IFlagSet } from './types';
import { IFbClient } from '@featbit/js-client-sdk';
import { ProviderState } from "./providerState";
/**
* The `FbProvider` is a component which accepts a config object which is used to
* initialize `@featbit/js-client-sdk`.
*
* This Provider does three things:
* - It initializes the FeatBit instance by calling `@featbit/js-client-sdk` init on `componentDidMount`
* - It saves all flags and the FeatBit instance in the context API
* - It subscribes to flag changes and propagate them through the context API
*
* Because the `@featbit/js-client-sdk` is only initialized on `componentDidMount`, your flags and the
* FeatBit are only available after your app has mounted. This can result in a flicker due to flag changes at
* startup time.
*
* This component can be used as a standalone provider. However, be mindful to only include the component once
* within your application. This provider is used inside the `withFbProviderHOC` and can be used instead to initialize
* the `@featbit/js-client-sdk`. For async initialization, check out the `asyncWithFbProvider` function
*/
declare class FbProvider extends Component<PropsWithChildren<ProviderConfig>, ProviderState> implements EnhancedComponent {
readonly state: Readonly<ProviderState>;
bootstrapFlags: IFlagSet;
constructor(props: ProviderConfig);
getReactOptions: () => {
useCamelCaseFlagKeys: boolean;
sendEventsOnFlagRead: boolean;
};
subscribeToChanges: (fbClient: IFbClient) => void;
onFailed: (fbClient: IFbClient, e: Error) => void;
onReady: (fbClient: IFbClient, reactOptions: any) => Promise<void>;
prepareFbClient: () => Promise<void>;
componentDidMount(): Promise<void>;
componentDidUpdate(prevProps: ProviderConfig): Promise<void>;
render(): React.JSX.Element;
}
export default FbProvider;