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: README.md
+61-20
Original file line number
Diff line number
Diff line change
@@ -54,15 +54,68 @@ You can use both to have different values on client-side and server-side.
54
54
55
55
# Usage
56
56
57
-
## A). Client-side only - simple use case and for development purposes (CSR)
57
+
## A). 🌟 **App directory** (new)
58
+
59
+
This package is ready for server-side use with [App Router](https://nextjs.org/docs/app/building-your-application/routing).
60
+
61
+
Refer to [`./example/README.md#App-router`](https://github.com/Unleash/unleash-client-nextjs/tree/main/example#app-router) for an implementation example.
It's possible to run this SDK in Next.js Edge Middleware. This is a great use case for A/B testing, where you can transparently redirect users to different pages based on a feature flag. Target pages can be statically generated, improving performance.
105
+
106
+
Refer to [`./example/README.md#Middleware`](https://github.com/Unleash/unleash-client-nextjs/tree/main/example#middleware) for an implementation example.
107
+
108
+
## C). Client-side only - simple use case and for development purposes (CSR)
58
109
59
110
Fastest way to get started is to connect frontend directly to Unleash.
60
111
You can find out more about direct [Front-end API access](https://docs.getunleash.io/reference/front-end-api) in our documentation,
61
112
including a guide on how to [setup a client-side SDK key](https://docs.getunleash.io/how-to/how-to-create-api-tokens).
62
113
114
+
Important: Hooks and provider are only available in `@unleash/nextjs/client`.
With `<FlagProvider />` in place you can now use hooks like: `useFlag`, `useVariant`, or `useFlagsStatus` to block rendering until flags are ready.
77
130
78
131
```jsx
79
-
import { useFlag } from"@unleash/nextjs";
132
+
import { useFlag } from"@unleash/nextjs/client";
80
133
81
134
constYourComponent= () => {
82
135
constisEnabled=useFlag("nextjs-example");
@@ -102,7 +155,7 @@ Optionally, you can configure `FlagProvider` with the `config` prop. It will tak
102
155
103
156
If you only plan to use [Unleash client-side React SDK](https://github.com/Unleash/proxy-client-react) now also works with Next.js. Check documentation there for more examples.
104
157
105
-
## B). Static Site Generation, optimized performance (SSG)
158
+
## D). Static Site Generation, optimized performance (SSG)
106
159
107
160
With same access as in the client-side example above you can resolve Unleash feature flags when building static pages.
108
161
@@ -155,7 +208,7 @@ The same approach will work for [ISR (Incremental Static Regeneration)](https://
155
208
156
209
Both `getDefinitions()` and `getFrontendFlags()` can take arguments overriding URL, token and other request parameters.
It's possible to run this SDK in Next.js Edge Middleware. This is a great use case for A/B testing, where you can transparently redirect users to different pages based on a feature flag. Target pages can be statically generated, improving performance.
256
-
257
-
See [`./example/README.md#Middleware`](https://github.com/Unleash/unleash-client-nextjs/blob/main/example/README.md#middleware)
258
-
259
306
# ⚗️ CLI (experimental)
260
307
261
308
You can use `unleash [action] [options]` in your `package.json``scripts` section, or with:
Unleash Next.js SDK can run on [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime) and in [Middleware](https://nextjs.org/docs/advanced-features/middleware). We are also interested in providing an example with [App Directory](https://beta.nextjs.org/docs/app-directory-roadmap).
298
-
299
-
## Known limitation
340
+
# Known limitation
300
341
301
-
- In current interation server-side SDK does not support metrics.
342
+
- In current interation **server-side SDK does not support metrics**.
302
343
- When used server-side, this SDK does not support the "Hostname" and "IP" strategies. Use custom context fields and constraints instead.
0 commit comments