• Returns the LDServerSession scoped to the current request.

    Returns LDServerSession | null

    The LDServerSession scoped to the current request, or null if no session has been created.

    Remarks

    NOTE: This function is only used to retrieve the session stored by createLDServerSession. You must call createLDServerSession before calling this function or it will return a null value.

    Example

    // app.tsx (entry point)
    import { createLDServerSession } from '@launchdarkly/react-sdk/server';
    const session = createLDServerSession(client, context);

    // component.ts
    import { useLDServerSession } from '@launchdarkly/react-sdk/server';

    export default function MyComponent() {
    const session = useLDServerSession();
    if (session) {
    const flagValue = await session.boolVariation('my-flag', false);
    return <div>{flagValue ? 'Yes' : 'No'}</div>;
    }
    return <div>Loading...</div>;
    }

Generated using TypeDoc