You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/sdk/react-universal/README.md
+26-43Lines changed: 26 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,62 +9,49 @@
9
9
> [!CAUTION]
10
10
> This library is a beta version and should not be considered ready for production use while this message is visible.
11
11
12
-
> **An idiomatic LaunchDarkly SDK which supports RSC, server side rendering and bootstrapping**:clap:
12
+
## Features
13
13
14
-
This SDK supports:
14
+
- Supports both React Server Components and Client Components
15
+
- Idiomatic server side rendering
16
+
- Bootstrapping out of the box
15
17
16
-
- React Server Components
17
-
- Server side rendering
18
-
- Bootstrapping
19
-
20
-
## Installation
18
+
## Install
21
19
22
20
```shell
23
21
# npm
24
-
npm i @launchdarkly/react-universal-sdk --save-dev
22
+
npm i @launchdarkly/react-universal-sdk
25
23
26
24
# yarn
27
25
yarn add -D @launchdarkly/react-universal-sdk
28
26
```
29
27
30
-
###Server API
28
+
## Server API
31
29
32
-
-`initNodeSdk` - Initializes the Node SDK on server startup using the [instrumentation hook](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation)
30
+
-`initNodeSdk` - Initializes the Node SDK on startup.
33
31
34
-
-`getBootstrap` - Returns a json suitable for bootstrapping the js sdk.
32
+
-`getBootstrap` - Produces suitable bootstrap the js sdk.
35
33
36
-
-`useLDClientRsc` - Use this to get an ldClient for Server Components.
34
+
-`useLDClientRsc` - Gets a suitable ld client for Server Components.
37
35
38
-
###Client API
36
+
## Client API
39
37
40
38
-`LDProvider` - The react context provider.
41
39
42
-
-`useLDClient` - Use this to get an ldClient for Client Components.
40
+
-`useLDClient` - Gets a suitable ld client for Client Components.
43
41
44
42
## Usage
45
43
46
-
1.Enable [instrumentationHook](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation) in `next.config.mjs`:
44
+
1.On server start, initialize the Node Server SDK. If you are using NextJS App Router, do this in `instrumentation.ts`. You'll need to enable the [instrumentationHook](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation):
47
45
48
46
```ts
49
-
/**@type{import('next').NextConfig}*/
50
-
const nextConfig = {
51
-
experimental: { instrumentationHook: true },
52
-
};
53
-
54
-
exportdefaultnextConfig;
55
-
```
56
-
57
-
2. Create a new file `instrumentation.ts` at the root of your project. This will initialize the Node Server SDK.
You will see both components are rendered on the server (view source on your browser). However, only Client Components
129
-
will respond to live changes.
112
+
You will see both Server and Client Components are rendered on the server (view source on your browser). However, only Client Components will respond to live changes because Server Components are excluded from the client bundle.
130
113
131
114
## Verifying SDK build provenance with the SLSA framework
> This is an experimental project to demonstrate the use of LaunchDarkly with Next.js App Router.
5
3
>
6
4
> This is designed for the App Router. Pages router is not supported.
7
5
8
-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) using App Router.
6
+
This example app uses the LaunchDarkly React Universal SDK. It features:
9
7
10
-
## Quickstart
8
+
- Server side rendering with both Server Components and Client Components.
9
+
- A Client Component example in [app/components/helloClientComponent.tsx](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-universal/example/app/components/helloClientComponent.tsx)
10
+
- A Server Component (RSC) example in [app/components/helloServerComponent.tsx](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-universal/example/app/components/helloServerComponent.tsx)
11
+
- Out of the box bootstrapping.
11
12
12
-
To run this project:
13
+
This is a [Next.js](https://nextjs.org/) project created with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) using App Router.
14
+
15
+
## Quickstart
13
16
14
-
1. Create an .env file at repo root.
15
-
2. Add your SDK key and client-side ID:
17
+
1. Rename `.example.env.local` to `.env.local` and use your LaunchDarkly SDK keys:
3. Replace `dev-test-flag` with your own flags in `app.tsx` and `LDButton.tsx`.
23
-
4.`yarn && yarn dev`
24
+
2. Either create `my-boolean-flag-1` in your LaunchDarkly environment or replace with your own flag in [helloClientComponent.tsx](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-universal/example/app/components/helloClientComponent.tsx) and [helloServerComponent.tsx](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-universal/example/app/components/helloServerComponent.tsx).
25
+
26
+
3. Finally:
27
+
28
+
```bash
29
+
npm i && npm run dev
30
+
31
+
# or
32
+
yarn && yarn dev
33
+
```
24
34
25
-
You should see your flag value rendered in the browser.
35
+
You will see both Server and Client Components are rendered on the server (view source on your browser). However, only Client Components will respond to live changes because Server Components are excluded from the client bundle.
0 commit comments