The LaunchDarkly client interface for React.

Hierarchy

Properties

logger: LDLogger

The logger configured as part of LDOptions during construction.

Remarks

For more information, read LDOptions.logger and LDLogger.

Returns

The configured LDLogger.

Methods

  • Add a hook to the client. In order to register a hook before the client starts, please use the hooks property of LDOptions.

    Hooks provide entrypoints which allow for observation of SDK functions.

    Parameters

    Returns void

  • Returns a map of all available flags to the current context's values.

    Returns LDFlagSet

    An object in which each key is a feature flag key and each value is the flag value. Note that there is no way to specify a default value for each flag as there is with variation, so any flag that cannot be evaluated will be undefined.

  • Determines the boolean variation of a feature flag.

    If the flag variation does not have a boolean value, defaultValue is returned.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: boolean

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns boolean

    The boolean value.

  • Determines the boolean variation of a feature flag, along with information about how it was calculated.

    The reason property of the result will also be included in analytics events, if you are capturing detailed event data for this flag.

    If the flag variation does not have a boolean value, defaultValue is returned. The reason will indicate an error of the type WRONG_KIND in this case.

    For more information, see the SDK reference guide.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: boolean

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns LDEvaluationDetailTyped<boolean>

    The result (as an ).

  • Shuts down the client and releases its resources, after delivering any pending analytics events.

    Returns Promise<void>

  • Flushes all pending analytics events.

    Normally, batches of events are delivered in the background at intervals determined by the flushInterval property of LDOptions. Calling flush() triggers an immediate delivery.

    Returns Promise<{
        error?: Error;
        result: boolean;
    }>

    A Promise which resolves once flushing is finished. You can inspect the result of the flush for errors.

  • Returns the client's current context.

    This is the context that was most recently passed to identify, or, if identify has never been called, this will be undefined.

    Returns undefined | LDContextStrict

  • Returns the error that caused initialization to fail, if any. Only set when getInitializationState() returns 'failed'.

    Returns undefined | Error

  • Returns the initialization state of the client. This function is helpful to determine whether LDClient can be used to evaluate flags on initial component render.

    Returns "initializing" | "failed" | "timeout" | "complete"

    The initialization state of the client.

    See

    LDWaitForInitializationResult for the possible values and their meaning

  • Returns whether the client is ready to evaluate flags. This is true when the client has completed initialization (successfully or with failure), or when bootstrap data was provided.

    Returns boolean

    Whether the client can evaluate flags.

  • Determines the json variation of a feature flag.

    This version may be favored in TypeScript versus variation because it returns an unknown type instead of any. unknown will require a cast before usage.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: unknown

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns unknown

    The json value.

  • Determines the json variation of a feature flag, along with information about how it was calculated.

    The reason property of the result will also be included in analytics events, if you are capturing detailed event data for this flag.

    This version may be favored in TypeScript versus variation because it returns an unknown type instead of any. unknown will require a cast before usage.

    For more information, see the SDK reference guide.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: unknown

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns LDEvaluationDetailTyped<unknown>

    The result (as an ).

  • Determines the numeric variation of a feature flag.

    If the flag variation does not have a numeric value, defaultValue is returned.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: number

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns number

    The numeric value.

  • Determines the numeric variation of a feature flag for a context, along with information about how it was calculated.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: number

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns LDEvaluationDetailTyped<number>

    The result (as an ).

    Remarks

    The reason property of the result will also be included in analytics events, if you are capturing detailed event data for this flag.

    If the flag variation does not have a numeric value, defaultValue is returned. The reason will indicate an error of the type WRONG_KIND in this case.

    For more information, see the SDK reference guide.

  • Removes an event listener. See on for the available event types.

    Parameters

    • key: string

      The name of the event for which to stop listening.

    • callback: ((...args) => void)

      The function to deregister.

        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    Returns void

  • Registers an event listener.

    Parameters

    • key: string

      The name of the event for which to listen.

    • callback: ((...args) => void)

      The function to execute when the event fires. The callback may or may not receive parameters, depending on the type of event.

        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    Returns void

    Remarks

    You can subscribe to one of the supported EventName:

    • "change": The client has received new feature flag data. This can happen either because you have switched contexts with identify, or because the client has a stream connection and has received a live change to a flag value (see below). The callback parameters are the context and an array of flag keys that have changed.

    • "error": General event for any kind of error condition during client operation. The callback parameters are the context and an Error object. Errors are also output by the logger at the error level.

    • "dataSourceStatus": Event indicating that there has been a change in the status of the data source. This will include the state of the data source as well any error information.

  • Subscribes to context changes triggered by identify(). The callback is invoked after each successful identify() call with the new resolved context.

    Parameters

    • callback: ((context) => void)

      Function called with the new context after each successful identify.

    Returns (() => void)

    An unsubscribe function. Call it to stop receiving notifications.

      • (): void
      • Subscribes to context changes triggered by identify(). The callback is invoked after each successful identify() call with the new resolved context.

        Returns void

        An unsubscribe function. Call it to stop receiving notifications.

  • Subscribes to initialization status changes triggered when the client is initialized.

    Parameters

    • callback: ((result) => void)

      Function called with the initialization result.

    Returns (() => void)

    An unsubscribe function. Call it to stop receiving notifications.

      • (): void
      • Subscribes to initialization status changes triggered when the client is initialized.

        Returns void

        An unsubscribe function. Call it to stop receiving notifications.

  • Specifies whether or not to open a streaming connection to LaunchDarkly for live flag updates.

    If this is true, the client will always attempt to maintain a streaming connection; if false, it never will. If you leave the value undefined (the default), the client will open a streaming connection if you subscribe to "change" or "change:flag-key" events (see LDClient.on).

    This can also be set as the streaming property of LDOptions.

    Parameters

    • Optional streaming: boolean
      Optional

    Returns void

  • Internal

    Returns whether flag keys should be converted to camelCase in useFlags(). Defaults to true when absent.

    Returns boolean

    Whether flag keys should be converted to camelCase.

    Remarks

    NOTE: This method is only used by useFlags() hook.

    Deprecated

    This method is deprecated and will be removed in a future major version.

  • Determines the string variation of a feature flag.

    If the flag variation does not have a string value, defaultValue is returned.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: string

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns string

    The string value.

  • Determines the string variation of a feature flag for a context, along with information about how it was calculated.

    Parameters

    • key: string

      The unique key of the feature flag.

    • defaultValue: string

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

    Returns LDEvaluationDetailTyped<string>

    The result (as an ).

    Remarks

    The reason property of the result will also be included in analytics events, if you are capturing detailed event data for this flag.

    If the flag variation does not have a string value, defaultValue is returned. The reason will indicate an error of the type WRONG_KIND in this case.

    For more information, see the SDK reference guide.

  • Track events for experiments.

    Parameters

    • key: string

      The name of the event, which may correspond to a goal in an experiment.

    • Optional data: any

      Additional information to associate with the event.

      Optional
    • Optional metricValue: number

      An optional numeric value that can be used by the LaunchDarkly experimentation feature in numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This field will also be returned as part of the custom event for Data Export.

      Optional

    Returns void

  • We recommend using strongly typed variation methods which perform type checks and handle type errors.

    Parameters

    • key: string

      The unique key of the feature flag.

    • Optional defaultValue: any

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

      Optional

    Returns any

    The flag's value.

    Remarks

    Determines the variation of a feature flag.

    In the client-side JavaScript SDKs, this is always a fast synchronous operation because all of the feature flag values for the current context have already been loaded into memory.

  • We recommend using strongly typed variation detail methods which perform type checks and handle type errors.

    Parameters

    • key: string

      The unique key of the feature flag.

    • Optional defaultValue: any

      The default value of the flag, to be used if the value is not available from LaunchDarkly.

      Optional

    Returns LDEvaluationDetail

    An LDEvaluationDetail object containing the value and explanation.

    Remarks

    Determines the variation of a feature flag for a context, along with information about how it was calculated.

    Note that this will only work if you have set withReasons to true in LDOptions.

    The reason property of the result will also be included in analytics events, if you are capturing detailed event data for this flag.

    For more information, see the SDK reference guide.

  • Returns a Promise that tracks the client's initialization state.

    The Promise will be resolved to a LDWaitForInitializationResult object containing the status of the waitForInitialization operation.

    Parameters

    Returns Promise<LDWaitForInitializationResult>

    A Promise that will be resolved to a LDWaitForInitializationResult object containing the status of the waitForInitialization operation.

    Example

    This example shows use of async/await syntax for specifying handlers:

        const result = await client.waitForInitialization({ timeout: 5 });

    if (result.status === 'complete') {
    doSomethingWithSuccessfullyInitializedClient();
    } else if (result.status === 'failed') {
    doSomethingForFailedStartup(result.error);
    } else if (result.status === 'timeout') {
    doSomethingForTimedOutStartup();
    }

    Remarks

    You can also use event listeners (on) for the same purpose: the event "initialized" indicates success, and "error" indicates an error.

Generated using TypeDoc