melodic-quill-31019
05/12/2022, 1:23 PMimport { ReactNode, useEffect } from "react";
import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";
import { useUser } from "src/lib/auth";
import useSWR from "swr";
const growthbook = new GrowthBook();
async function fetcher() {
const res = await fetch(process.env.NEXT_PUBLIC_GROWTHBOOK_FEATURES_ENDPOINT);
if (res.status !== 200) {
return null;
}
const result = await res.json();
return result?.features;
}
export default function MyGrowthBookProvider({
children,
}: {
children: ReactNode;
}) {
const { data: featureFlags } = useSWR("feature-flags", fetcher);
const user = useUser();
useEffect(() => {
growthbook.setFeatures(featureFlags);
}, [featureFlags]);
useEffect(() => {
growthbook.setAttributes({
id: user.data?.id,
});
}, [user.data]);
return (
<GrowthBookProvider growthbook={growthbook}>{children}</GrowthBookProvider>
);
}
<MyGrowthBookProvider />
is used in _app.tsx
(wrapping <Component />
)
The feature flagging works fine, only the dev tool doesn't have any effect.future-teacher-7046
_growthbook._forcedFeatureValues
to see if it's being set.melodic-quill-31019
05/12/2022, 1:36 PMfuture-teacher-7046
future-teacher-7046
new GrowthBook()
?melodic-quill-31019
05/12/2022, 2:28 PMnew GrowthBook()
. I had another one running in a _middleware.ts
(which should not run in the frontend), but I removed it to be sure that this is not the problem.Open source platform for stress free deployments, measured impact, and smarter decisions.
Powered by