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
BREAKING CHANGES:
- All imports that were previously under the package root (`@spotify-confidence/react`) are now accessible under `@spotify-confidence/react/client`.
- Previously, when you did `useConfidence`, the returned instance would be augmented with extra hook like functions such as `useFlag`. These have been removed and you should just use the exported top level hooks.
---------
Co-authored-by: Nicklas Lundin <[email protected]>
The Confidence React integration has a Provider that needs to be initialized. It accepts a Confidence instance and should wrap your component tree.
19
+
The Confidence React integration has a Provider that needs to be initialized. It accepts a Confidence instance and should wrap your component tree. Here's an example for client-side rendering:
environment: 'client',// Note: For client-side rendering
28
30
timeout: 1000,
29
31
});
30
32
@@ -39,6 +41,8 @@ function App() {
39
41
}
40
42
```
41
43
44
+
For server-side rendering setup, see the [Server-Side Rendering Support](#server-side-rendering-support) section below.
45
+
42
46
Anywhere in the sub-tree under the `ConfidenceProvider` you can now access the confidence instance with the `useConfidence()` hook. The hook actually returns an instance of `ConfidenceReact` which is a wrapper around the normal `Confidence` API with some slight adaptations to integrate better with React. You can read more about the differences in the following sections.
43
47
44
48
### Managing context
@@ -66,6 +70,120 @@ The hooks are also reactive so that if the context changes, any components using
66
70
67
71
If the hooks can't resolve the flag values withing the timeout specified on the Confidence instance, they will instead return the default value.
68
72
73
+
### Server-Side Rendering Support (experimental)
74
+
75
+
The Confidence React SDK now supports server-side rendering (SSR) and React Server Components (RSC) for instance in Next.js. The SDK provides separate entry points for client and server components:
76
+
77
+
-`@spotify-confidence/react/client` - For client components
78
+
-`@spotify-confidence/react/server` - For server components
79
+
80
+
When using the SDK in a server environment:
81
+
82
+
1. Create a Confidence instance for server using the React.cache as the scope in CacheOptions.
83
+
2. Provide an accessor for the Confidence instance using `withContext`.
84
+
3. Use direct flag evaluation in server components.
85
+
86
+
Here's an example of how to use Confidence in a Next.js application:
The event tracking API is available on the Confidence instance as usual. See the [SDK Readme](https://github.com/spotify/confidence-sdk-js/blob/main/packages/sdk/README.md#event-tracking) for details.
0 commit comments