@togglely/sdk-react 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @togglely/sdk-react
|
|
|
12
12
|
|
|
13
13
|
### Provider
|
|
14
14
|
|
|
15
|
-
Wrap your app with `TogglelyProvider
|
|
15
|
+
Wrap your app with `TogglelyProvider`. You can provide an `initialContext` for multi-tenant setups:
|
|
16
16
|
|
|
17
17
|
```tsx
|
|
18
18
|
import { TogglelyProvider } from '@togglely/sdk-react';
|
|
@@ -23,6 +23,10 @@ function App() {
|
|
|
23
23
|
apiKey="your-api-key"
|
|
24
24
|
environment="production"
|
|
25
25
|
baseUrl="https://your-togglely-instance.com"
|
|
26
|
+
initialContext={{
|
|
27
|
+
tenantId: 'customer-123',
|
|
28
|
+
plan: 'premium'
|
|
29
|
+
}}
|
|
26
30
|
>
|
|
27
31
|
<MyApp />
|
|
28
32
|
</TogglelyProvider>
|
|
@@ -30,8 +34,49 @@ function App() {
|
|
|
30
34
|
}
|
|
31
35
|
```
|
|
32
36
|
|
|
37
|
+
### Server Side Rendering (SSR) & Next.js
|
|
38
|
+
|
|
39
|
+
For SSR, use `getTogglelyState` to fetch toggles before the page renders:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
// Next.js getServerSideProps example
|
|
43
|
+
import { getTogglelyState } from '@togglely/sdk-react';
|
|
44
|
+
|
|
45
|
+
export async function getServerSideProps() {
|
|
46
|
+
const toggles = await getTogglelyState({
|
|
47
|
+
apiKey: process.env.TOGGLELY_API_KEY,
|
|
48
|
+
environment: 'production',
|
|
49
|
+
baseUrl: 'https://your-togglely-instance.com'
|
|
50
|
+
}, {
|
|
51
|
+
tenantId: 'customer-123'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return { props: { initialToggles: toggles } };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Then pass to Provider to avoid flickering
|
|
58
|
+
<TogglelyProvider initialToggles={props.initialToggles} ...>
|
|
59
|
+
```
|
|
60
|
+
|
|
33
61
|
### Hooks
|
|
34
62
|
|
|
63
|
+
#### `useTogglelyClient()`
|
|
64
|
+
|
|
65
|
+
Access the core client to update context dynamically:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
function LoginComponent() {
|
|
69
|
+
const client = useTogglelyClient();
|
|
70
|
+
|
|
71
|
+
const handleLogin = (user) => {
|
|
72
|
+
client.setContext({
|
|
73
|
+
userId: user.id,
|
|
74
|
+
tenantId: user.companyId
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
35
80
|
#### `useToggle(key, defaultValue)`
|
|
36
81
|
|
|
37
82
|
Check if a boolean feature toggle is enabled:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@togglely/sdk-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "React SDK for Togglely - Feature toggles with hooks",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -35,4 +35,4 @@
|
|
|
35
35
|
"tslib": "^2.6.2",
|
|
36
36
|
"typescript": "^5.3.3"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|