React SDK
Provider + hooks that wrap @getfluxly/browser for React apps and any React-based framework. SSR-safe, the provider's effects are no-ops on the server, so importing from a React Server Component never touches window.
Install
npm install @getfluxly/react @getfluxly/browser
Quick start
import { GFluxProvider, useTrack } from "@getfluxly/react";
function Root() {
return (
<GFluxProvider apiKey={process.env.NEXT_PUBLIC_GFLUX_API_KEY}>
<App />
</GFluxProvider>
);
}
function App() {
const track = useTrack();
return (
<button onClick={() => track("cta_clicked", { id: "hero" })}>
Get started
</button>
);
}
Hooks
| Hook | Returns | Notes |
| --- | --- | --- |
| useGFlux() | GFluxBrowser \| null | The raw SDK instance, or null during SSR / before mount |
| useTrack() | (name, props?) => void | Stable identity across re-renders |
| useIdentify() | (externalId, traits?) => void | |
| usePage() | (properties?) => void | Manually fire a page view |
| useConsent() | { status, optIn, optOut } | Status is unknown / opted_in / opted_out |
Provider props
| Prop | Notes |
| --- | --- |
| apiKey | Publishable key |
| apiHost | Defaults to https://api.getfluxly.com |
| config | Forwarded to initGFlux (debounce, sampling, etc.) |
| client | Inject your own SDK instance, useful for tests |
apiKey is captured at first mount. Swapping it later warns in dev and is ignored; remount the provider to switch.
Use with Next.js
The provider must run in a client component. Wrap it under a "use client" boundary or use @getfluxly/next which ships a Next-aware version. See the Next SDK.