@replanejs/react 0.1.1 → 0.7.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 +185 -0
  2. package/package.json +3 -5
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # @replanejs/react
2
+
3
+ React SDK for [Replane](https://github.com/replane-dev/replane-javascript) - feature flags and remote configuration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @replanejs/react
9
+ # or
10
+ pnpm add @replanejs/react
11
+ # or
12
+ yarn add @replanejs/react
13
+ ```
14
+
15
+ ## Requirements
16
+
17
+ - React 18.0.0 or higher
18
+ - Node.js 18.0.0 or higher
19
+
20
+ ## Quick Start
21
+
22
+ ```tsx
23
+ import { ReplaneProvider, useConfig } from '@replanejs/react';
24
+
25
+ function App() {
26
+ return (
27
+ <ReplaneProvider
28
+ options={{
29
+ baseUrl: 'https://your-replane-server.com',
30
+ sdkKey: 'your-sdk-key',
31
+ }}
32
+ loader={<div>Loading...</div>}
33
+ >
34
+ <MyComponent />
35
+ </ReplaneProvider>
36
+ );
37
+ }
38
+
39
+ function MyComponent() {
40
+ const isFeatureEnabled = useConfig<boolean>('feature-flag-name');
41
+
42
+ return (
43
+ <div>
44
+ {isFeatureEnabled ? 'Feature is enabled!' : 'Feature is disabled'}
45
+ </div>
46
+ );
47
+ }
48
+ ```
49
+
50
+ ## API
51
+
52
+ ### ReplaneProvider
53
+
54
+ Provider component that makes the Replane client available to your component tree. Supports three usage patterns:
55
+
56
+ #### 1. With options (recommended)
57
+
58
+ The provider creates and manages the client internally:
59
+
60
+ ```tsx
61
+ <ReplaneProvider
62
+ options={{
63
+ baseUrl: 'https://your-replane-server.com',
64
+ sdkKey: 'your-sdk-key',
65
+ }}
66
+ loader={<LoadingSpinner />}
67
+ onError={(error) => console.error('Failed to initialize:', error)}
68
+ >
69
+ <App />
70
+ </ReplaneProvider>
71
+ ```
72
+
73
+ #### 2. With pre-created client
74
+
75
+ Use this when you need more control over client lifecycle:
76
+
77
+ ```tsx
78
+ import { createReplaneClient } from '@replanejs/sdk';
79
+
80
+ const client = await createReplaneClient({
81
+ baseUrl: 'https://your-replane-server.com',
82
+ sdkKey: 'your-sdk-key',
83
+ });
84
+
85
+ <ReplaneProvider client={client}>
86
+ <App />
87
+ </ReplaneProvider>
88
+ ```
89
+
90
+ #### 3. With Suspense
91
+
92
+ Integrates with React Suspense for loading states:
93
+
94
+ ```tsx
95
+ <Suspense fallback={<LoadingSpinner />}>
96
+ <ReplaneProvider
97
+ options={{
98
+ baseUrl: 'https://your-replane-server.com',
99
+ sdkKey: 'your-sdk-key',
100
+ }}
101
+ suspense
102
+ >
103
+ <App />
104
+ </ReplaneProvider>
105
+ </Suspense>
106
+ ```
107
+
108
+ ### useConfig
109
+
110
+ Hook to retrieve a configuration value. Automatically subscribes to updates and re-renders when the value changes.
111
+
112
+ ```tsx
113
+ function MyComponent() {
114
+ // Basic usage
115
+ const theme = useConfig<string>('theme');
116
+
117
+ // With evaluation context
118
+ const discount = useConfig<number>('discount-percentage', {
119
+ context: {
120
+ userId: '123',
121
+ isPremium: true,
122
+ },
123
+ });
124
+
125
+ return <div>Theme: {theme}, Discount: {discount}%</div>;
126
+ }
127
+ ```
128
+
129
+ ### useReplane
130
+
131
+ Hook to access the underlying Replane client directly:
132
+
133
+ ```tsx
134
+ function MyComponent() {
135
+ const { client } = useReplane();
136
+
137
+ const handleClick = () => {
138
+ // Access client methods directly
139
+ const value = client.get('some-config');
140
+ console.log(value);
141
+ };
142
+
143
+ return <button onClick={handleClick}>Get Config</button>;
144
+ }
145
+ ```
146
+
147
+ ### clearSuspenseCache
148
+
149
+ Utility function to clear the suspense cache. Useful for testing or forcing re-initialization:
150
+
151
+ ```tsx
152
+ import { clearSuspenseCache } from '@replanejs/react';
153
+
154
+ // Clear cache for specific options
155
+ clearSuspenseCache({
156
+ baseUrl: 'https://your-replane-server.com',
157
+ sdkKey: 'your-sdk-key',
158
+ });
159
+
160
+ // Clear entire cache
161
+ clearSuspenseCache();
162
+ ```
163
+
164
+ ## TypeScript
165
+
166
+ The SDK is fully typed. You can provide a type parameter to get type-safe configuration values:
167
+
168
+ ```tsx
169
+ interface MyConfig {
170
+ theme: 'light' | 'dark';
171
+ maxItems: number;
172
+ features: {
173
+ analytics: boolean;
174
+ notifications: boolean;
175
+ };
176
+ }
177
+
178
+ // Type-safe hooks
179
+ const { client } = useReplane<MyConfig>();
180
+ const theme = useConfig<MyConfig['theme']>('theme');
181
+ ```
182
+
183
+ ## License
184
+
185
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replanejs/react",
3
- "version": "0.1.1",
3
+ "version": "0.7.0",
4
4
  "description": "React SDK for Replane - feature flags and remote configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,11 +40,10 @@
40
40
  "react": ">=18.0.0"
41
41
  },
42
42
  "dependencies": {
43
- "@replanejs/sdk": "0.6.2"
43
+ "@replanejs/sdk": "0.7.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@testing-library/jest-dom": "^6.9.1",
47
- "bumpp": "^10.1.0",
48
47
  "@testing-library/react": "^16.3.1",
49
48
  "@types/node": "^22.19.3",
50
49
  "@types/react": "^18.2.0",
@@ -67,7 +66,6 @@
67
66
  "dev": "tsdown --watch",
68
67
  "typecheck": "tsc --noEmit",
69
68
  "test": "vitest run",
70
- "test:watch": "vitest",
71
- "release": "pnpm run build && bumpp && npm publish"
69
+ "test:watch": "vitest"
72
70
  }
73
71
  }