Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";
import { isExperimentationEnabled } from "experimentation";
import { useAuthContext } from "features/auth/AuthProvider";
import { ReactNode, useEffect, useMemo } from "react";
export default function ExperimentationProvider({
children,
}: {
children: ReactNode;
}) {
const { authState } = useAuthContext();
const gb = useMemo(
() =>
new GrowthBook({
apiHost: process.env.NEXT_PUBLIC_GROWTHBOOK_API_HOST,
clientKey: process.env.NEXT_PUBLIC_GROWTHBOOK_CLIENT_KEY,
enableDevMode: process.env.NEXT_PUBLIC_COUCHERS_ENV !== "prod",
}),
[],
);
useEffect(() => {
Iif (isExperimentationEnabled()) {
gb.init({ timeout: 2000 });
}
return () => {
gb.destroy();
};
}, [gb]);
useEffect(() => {
gb.setAttributes({
id: authState.userId?.toString() ?? undefined,
});
}, [gb, authState.userId]);
return <GrowthBookProvider growthbook={gb}>{children}</GrowthBookProvider>;
}
|