Skip to content

Commit e08abc5

Browse files
committed
docs: fixing up documentation for release
1 parent d766f39 commit e08abc5

File tree

11 files changed

+191
-56
lines changed

11 files changed

+191
-56
lines changed

packages/sdk/react/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
1717
☝️☝️☝️
1818

19+
## Getting started
20+
Refer to the [SDK documentation](https://launchdarkly.com/docs/sdk/client-side/react/react-web#get-started) for instructions on getting started with using the SDK.
21+
1922
## About LaunchDarkly
2023

2124
- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:

packages/sdk/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"launchdarkly",
1414
"react",
1515
"isomorphic",
16+
"react-server-components",
1617
"nextjs",
1718
"remix"
1819
],

packages/sdk/react/src/client/LDClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface LDReactClient extends LDClient {
5959
/**
6060
* Returns whether the client is ready to evaluate flags. This is true when the client
6161
* has completed initialization (successfully or with failure), or when bootstrap data
62-
* was provided (flags are available immediately via `presetFlags`).
62+
* was provided.
6363
*
6464
* @returns {boolean} Whether the client can evaluate flags.
6565
*/
@@ -68,8 +68,8 @@ export interface LDReactClient extends LDClient {
6868
/**
6969
* @internal
7070
*
71-
* Returns whether flag keys should be converted to camelCase in `useFlags()` and resolved from camelCase
72-
* in the individual variation hooks. Defaults to `true` when absent.
71+
* Returns whether flag keys should be converted to camelCase in `useFlags()`.
72+
* Defaults to `true` when absent.
7373
*
7474
* @remarks
7575
* **NOTE:** This method is only used by `useFlags()` hook.

packages/sdk/react/src/client/LDOptions.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ export interface LDReactProviderOptions {
6161
deferInitialization?: boolean;
6262

6363
/**
64-
* This option allow developers to provide their own named react context for
65-
* the launchdarkly client. This is useful for cases where you want to have multiple
64+
* This option allows developers to provide their own named react context for
65+
* the LaunchDarkly client. This is useful for cases where you want to have multiple
6666
* clients in the same application. If not provided, the default context will be used.
6767
*
68-
* @see {@link LDReactClientContext} for the possible values and their meaning
69-
*
70-
* @returns {LDReactClientContext} The react context for the LaunchDarkly client.
68+
* @see {@link LDReactClientContext}
7169
*/
7270
reactContext?: LDReactClientContext;
7371

packages/sdk/react/src/client/LDReactClient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { LDReactClientOptions } from './LDOptions';
2929
*
3030
* @example
3131
* ```tsx
32-
* import { createClient } from '@launchdarkly/react';
32+
* import { createClient } from '@launchdarkly/react-sdk';
3333
* const client = createClient(clientSideID, context, options);
3434
*
3535
* await client.start();

packages/sdk/react/src/client/hooks/useVariationCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export default function useVariationCore<T, R = T>(
1717
// effect hook. These are purposely not dependencies of the effect hook as
1818
// they should not trigger any changes to the hook state.
1919
const defaultValueRef = useRef(defaultValue);
20-
defaultValueRef.current = defaultValue;
2120
const evaluateRef = useRef(evaluate);
21+
22+
defaultValueRef.current = defaultValue;
2223
evaluateRef.current = evaluate;
2324

2425
const didMountRef = useRef(false);

packages/sdk/react/src/client/provider/LDReactContext.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,34 @@ import { createContext } from 'react';
44

55
import type { LDReactClientContext, LDReactClientContextValue } from '../LDClient';
66

7-
// initializes a new context for the LaunchDarkly client. The sole usage of this function
8-
// is to create a new context so that it could be referenced and managed by the
9-
// application. This is a common pattern in React to create a new context for a
10-
// specific purpose.
7+
/**
8+
* Creates a new LaunchDarkly React context.
9+
*
10+
* @remarks
11+
* This function can be used to create different LaunchDarkly contexts for the same
12+
* application.
13+
*
14+
* **NOTE:** This function is not necessary if you are only using a single LaunchDarkly environment.
15+
* If that is the case, you can use the {@link LDReactContext} directly.
16+
*
17+
* @returns A new React context for the LaunchDarkly client.
18+
*/
1119
export function initLDReactContext(): LDReactClientContext {
1220
return createContext<LDReactClientContextValue>(null as any);
1321
}
1422

1523
/**
16-
* The LaunchDarkly React context.
24+
* The default LaunchDarkly React context.
25+
*
26+
* @example
27+
* ```tsx
28+
* import { LDReactContext, useLDClient } from '@launchdarkly/react-sdk';
29+
*
30+
* function MyComponent() {
31+
* const client = useLDClient(LDReactContext);
32+
* const flagValue = client.boolVariation('my-flag', false);
33+
* return <div>{flagValue ? 'on' : 'off'}</div>;
34+
* }
35+
* ```
1736
*/
1837
export const LDReactContext: LDReactClientContext = initLDReactContext();

packages/sdk/react/src/client/provider/LDReactProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { LDReactContext } from './LDReactContext';
1111
* Creates a new LaunchDarkly React provider wrapping an existing client instance.
1212
*
1313
* @remarks
14-
* **NOTE:** We recommend using the convenience factory function {@link createLDReactProvider}
14+
* **NOTE:** We recommend using the factory function {@link createLDReactProvider}
1515
* instead of this function if you can.
1616
*
1717
* This factory function is provided to allow the caller to use an existing client

packages/sdk/react/src/server/LDIsomorphicProvider.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export interface LDIsomorphicProviderProps {
4040
* @remarks
4141
* **NOTE:** This component is designed to be used in conjunction with {@link LDIsomorphicClientProvider}
4242
* in a server component to compute the bootstrap data and render this provider automatically.
43-
*
44-
* See the `server-only` example for how to use this component.
4543
*/
4644
export async function LDIsomorphicProvider({
4745
session,

packages/sdk/react/src/server/LDServerSession.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ import { LDContext, type LDFlagsStateOptions } from '@launchdarkly/js-server-sdk
55
import { LDServerSession } from './LDClient';
66
import { LDServerBaseClient } from './LDServerBaseClient';
77

8-
// cache() creates a per-request memoized store — each React render tree (request)
8+
// Creates a per-request memoized store — each React render tree (request)
99
// gets its own isolated instance. The store is populated by createLDServerSession
1010
// and read by useLDServerSession.
1111
const withCache = cache(() => ({ session: null as LDServerSession | null }));
1212

13-
/**
14-
* Boundary check for server only code. Given that we are assuming a React ecosystem,
15-
* simply checking for the presence of window should be sufficient.
16-
*/
1713
function isServer(): boolean {
1814
return typeof window === 'undefined';
1915
}
@@ -35,10 +31,10 @@ function isServer(): boolean {
3531
* ```ts
3632
* // lib/ld-server.ts
3733
* import { init } from '@launchdarkly/node-server-sdk';
38-
* import { createLDServerSession } from '@launchdarkly/react-sdk/server';
34+
* import { createLDServerWrapper } from '@launchdarkly/react-sdk/server';
3935
*
4036
* const ldBaseClient = await init(process.env.LAUNCHDARKLY_SDK_KEY || '');
41-
* export const serverSession = createLDServerSession(ldBaseClient, defaultContext);
37+
* export const serverSession = createLDServerWrapper(ldBaseClient, defaultContext);
4238
* ```
4339
*
4440
* @param client Any LaunchDarkly server SDK client that satisfies {@link LDServerBaseClient}.

0 commit comments

Comments
 (0)