@togglely/sdk-react 1.0.0

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.
Files changed (2) hide show
  1. package/README.md +113 -0
  2. package/package.json +38 -0
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @togglely/sdk-react
2
+
3
+ React SDK for Togglely - Feature toggles with hooks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @togglely/sdk-react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Provider
14
+
15
+ Wrap your app with `TogglelyProvider`:
16
+
17
+ ```tsx
18
+ import { TogglelyProvider } from '@togglely/sdk-react';
19
+
20
+ function App() {
21
+ return (
22
+ <TogglelyProvider
23
+ apiKey="your-api-key"
24
+ environment="production"
25
+ baseUrl="https://your-togglely-instance.com"
26
+ >
27
+ <MyApp />
28
+ </TogglelyProvider>
29
+ );
30
+ }
31
+ ```
32
+
33
+ ### Hooks
34
+
35
+ #### `useToggle(key, defaultValue)`
36
+
37
+ Check if a boolean feature toggle is enabled:
38
+
39
+ ```tsx
40
+ function MyComponent() {
41
+ const isEnabled = useToggle('new-feature', false);
42
+ return isEnabled ? <NewFeature /> : <OldFeature />;
43
+ }
44
+ ```
45
+
46
+ #### `useStringToggle(key, defaultValue)`
47
+
48
+ Get a string toggle value:
49
+
50
+ ```tsx
51
+ const message = useStringToggle('welcome-message', 'Hello');
52
+ ```
53
+
54
+ #### `useNumberToggle(key, defaultValue)`
55
+
56
+ Get a number toggle value:
57
+
58
+ ```tsx
59
+ const limit = useNumberToggle('max-items', 10);
60
+ ```
61
+
62
+ #### `useJSONToggle(key, defaultValue)`
63
+
64
+ Get a JSON toggle value:
65
+
66
+ ```tsx
67
+ const config = useJSONToggle('app-config', { theme: 'light' });
68
+ ```
69
+
70
+ #### `useToggles()`
71
+
72
+ Get all toggles:
73
+
74
+ ```tsx
75
+ const toggles = useToggles();
76
+ // toggles = { 'new-feature': { value: true, enabled: true }, ... }
77
+ ```
78
+
79
+ #### `useTogglelyState()`
80
+
81
+ Get the SDK state:
82
+
83
+ ```tsx
84
+ const state = useTogglelyState();
85
+ // state = { isReady: true, isOffline: false, lastError: null, lastFetch: Date }
86
+ ```
87
+
88
+ ### Components
89
+
90
+ #### `FeatureToggle`
91
+
92
+ Conditionally render content:
93
+
94
+ ```tsx
95
+ import { FeatureToggle } from '@togglely/sdk-react';
96
+
97
+ <FeatureToggle toggle="new-feature" fallback={<OldFeature />}>
98
+ <NewFeature />
99
+ </FeatureToggle>
100
+ ```
101
+
102
+ ### SSR Support
103
+
104
+ Pass initial toggles for server-side rendering:
105
+
106
+ ```tsx
107
+ <TogglelyProvider
108
+ apiKey="your-api-key"
109
+ environment="production"
110
+ baseUrl="https://your-togglely-instance.com"
111
+ initialToggles={{ 'new-feature': true }}
112
+ >
113
+ ```
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@togglely/sdk-react",
3
+ "version": "1.0.0",
4
+ "description": "React SDK for Togglely - Feature toggles with hooks",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc && rollup -c",
13
+ "test": "jest"
14
+ },
15
+ "keywords": [
16
+ "feature-flags",
17
+ "feature-toggles",
18
+ "togglely",
19
+ "react",
20
+ "hooks"
21
+ ],
22
+ "author": "Togglely",
23
+ "license": "MIT",
24
+ "peerDependencies": {
25
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
26
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
27
+ },
28
+ "dependencies": {
29
+ "@togglely/sdk-core": "^1.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@rollup/plugin-typescript": "^11.1.5",
33
+ "@types/react": "^18.2.45",
34
+ "rollup": "^4.9.1",
35
+ "tslib": "^2.6.2",
36
+ "typescript": "^5.3.3"
37
+ }
38
+ }