brief-football-97996
03/20/2023, 6:30 PMgetServerSideProps
. Is there something we’re missing with next.js 13 that would inhibit SSR?fresh-football-47124
brief-football-97996
03/20/2023, 8:39 PMexport const getServerSideProps: GetServerSideProps = async (context) => {
const gbContext = getServerSideGrowthBookContext(context);
const gb = new GrowthBook(gbContext);
await gb.loadFeatures({ timeout: 1000 });
const feature1Enabled = gb.isOn("feature1");
const feature2Value = gb.getFeatureValue("feature2", "fallback");
return {
props: {
feature1Enabled,
feature2Value,
},
};
};
fresh-football-47124
future-teacher-7046
brief-football-97996
03/20/2023, 9:32 PMfuture-teacher-7046
brief-football-97996
03/21/2023, 1:59 PMable-raincoat-11721
05/01/2023, 9:03 PM// GrowthbookProvider.tsx
export default async function GrowthbookProvider({
children,
}: Props) {
const response = await fetch(`<GROWTHBOOK_API_HOST>/api/features/<GROWTHBOOK_CLIENT_KEY>`,
{
next: {
revalidate: 0,
},
}
);
const { features } = (await response.json()) as { features: AppFeatures };
return (
<GrowthBookClientProvider initialFeatures={features}>
{children}
</GrowthBookClientProvider>
);
}
// GrowthBookClientProvider.tsx
"use client";
//...
type Props = {
children: ReactNode;
initialFeatures: AppFeatures | undefined;
};
export default function GrowthBookClientProvider({
children,
initialFeatures,
}: Props) {
const [growthbook] = useState(
() =>
new GrowthBook<AppFeatures>({
enableDevMode: true,
// @ts-expect-error Record<string, FeatureDefinition<any>>
features: initialFeatures,
trackingCallback(experiment, result) {
console.log("Tracking", experiment, result);
},
})
);
return (
<GrowthBookProvider growthbook={growthbook}>{children}</GrowthBookProvider>
);
}
// app/Layout.tsx
export default function Layout({ children }: Props) {
return (
<html lang="en">
<body>
<GrowthBookProvider>
<Nav />
{children}
<Footer />
</GrowthBookProvider>
</body>
</html>
);
}
fresh-football-47124
able-raincoat-11721
05/01/2023, 10:00 PMfresh-football-47124
able-raincoat-11721
05/01/2023, 10:01 PM