The LDServerSession scoped to the current request, or null if no session has been created.
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.
// 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
Returns the LDServerSession scoped to the current request.