@obelism/improve-sdk-react 0.2.0 → 0.3.1
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 +93 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1 +1,94 @@
|
|
|
1
1
|
# Obelism Improve React SDK
|
|
2
|
+
|
|
3
|
+
The React SDK sits around the [Javascript Client SDK](https://improve.obelism.studio/docs/sdk/javascript#client) and gives React specific handlers.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @obelism/improve-sdk-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
In your config folder create the following file: `improveClient.ts`
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generateImproveProvider } from '@obelism/improve-sdk-react'
|
|
17
|
+
|
|
18
|
+
export default generateImproveProvider(...)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
### generateImproveProvider
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
generateImproveProvider(improveArgs: {
|
|
27
|
+
organizationId: string
|
|
28
|
+
environment: 'develop' | 'staging' | 'production'
|
|
29
|
+
config?: Configuration
|
|
30
|
+
fetchTimeout?: number
|
|
31
|
+
}) => ({
|
|
32
|
+
ImproveProvider,
|
|
33
|
+
usePostAnalytic,
|
|
34
|
+
useTestValue,
|
|
35
|
+
useFlagValue
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Setup function that generates the React component and hooks.
|
|
40
|
+
|
|
41
|
+
### ImproveProvider
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
<ImproveProvider>
|
|
45
|
+
{children}
|
|
46
|
+
</ImproveProvider>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
On mount this automatically fetches the ImproveSDK and the config if not provided initially. Exposes a context that is used to populate data to the hooks down the component tree.
|
|
50
|
+
|
|
51
|
+
### useFlagValue
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const value: string = useFlagValue(flagSlug: string)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Wrapper around [getFlagValue](https://improve.obelism.studio/docs/sdk/javascript#getflagvalue) that's passed down when the context is setup.
|
|
58
|
+
|
|
59
|
+
### useTestValue
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const value: string = useTestValue(testSlug: string)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Wrapper around [getTestValue](https://improve.obelism.studio/docs/sdk/javascript#gettestvalue) that's passed down when the context is setup.
|
|
66
|
+
|
|
67
|
+
### usePostAnalytic
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const postAnalytic = usePostAnalytic()
|
|
71
|
+
|
|
72
|
+
<button onClick={() => postAnalytic(testSlug: string, eventSlug: string, message: string)} />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Wrapper around [postAnalytic](https://improve.obelism.studio/docs/sdk/javascript#postanalytic) that's passed down when the context is setup.
|
|
76
|
+
|
|
77
|
+
## NextJS App router
|
|
78
|
+
|
|
79
|
+
For NextJS we need to make sure the generated provider is marked as a client component. For this we need to declare the `ImproveProvider` within the file we declare `"use client"`.
|
|
80
|
+
|
|
81
|
+
This is needed because the ImproveProvider uses an `useEffect` to fetch load the JS SDK async and fetch the config async if needed. After it's setup it uses context to pass the data down.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
'use client'
|
|
85
|
+
|
|
86
|
+
import { generateImproveProvider } from 'utils/generateImproveProvider'
|
|
87
|
+
|
|
88
|
+
const improveReact = generateImproveProvider(...)
|
|
89
|
+
|
|
90
|
+
export const ImproveProvider = improveReact.ImproveProvider
|
|
91
|
+
export const useTestValue = improveReact.useTestValue
|
|
92
|
+
export const useFlagValue = improveReact.useFlagValue
|
|
93
|
+
export const usePostAnalytic = improveReact.usePostAnalytic
|
|
94
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obelism/improve-sdk-react",
|
|
3
3
|
"description": "Obelism Improve React SDK",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ab-tests",
|
|
7
7
|
"feature-flags",
|
|
@@ -61,6 +61,6 @@
|
|
|
61
61
|
"react": "^18.2.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@obelism/improve-sdk": "^0.
|
|
64
|
+
"@obelism/improve-sdk": "^0.3.1"
|
|
65
65
|
}
|
|
66
66
|
}
|