Function createLDServerWrapper

  • Creates a LaunchDarkly server SDK client that is scoped to a specific context.

    Parameters

    Returns LDServerSession

    An LDServerSession scoped to the given context.

    Remarks

    NOTE: We recommend using the createLDServerSession function to create your server session instead of directly calling this function.

    This function is provided to allow the caller to have more control over handling their scoped LD client. If using this function, the caller is responsible for managing the lifecycle of the created wrapped client.

    Throws

    If called in a browser environment. This function must only be called on the server. Ensure the module that calls this is not imported from client components.

    Example

    // lib/ld-server.ts
    import { init } from '@launchdarkly/node-server-sdk';
    import { createLDServerWrapper } from '@launchdarkly/react-sdk/server';

    const ldBaseClient = await init(process.env.LAUNCHDARKLY_SDK_KEY || '');
    export const serverSession = createLDServerWrapper(ldBaseClient, defaultContext);

Generated using TypeDoc