React SDK
The React SDK sits around the Javascript Client SDK and gives React specific handlers.
Install
Setup
In your config folder create the following file: improveClient.ts
API
generateImproveProvider
Setup function that generates the React component and hooks.
ImproveProvider
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.
useFlagValue
Wrapper around getFlagValue that's passed down when the context is setup.
useTestValue
Wrapper around getTestValue that's passed down when the context is setup.
usePostAnalytic
Wrapper around postAnalytic that's passed down when the context is setup.
NextJS App router
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"
.
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.