This message was deleted.
# ask-questions
w
This message was deleted.
h
Copy code
"use client";

import {
  GrowthBook,
  GrowthBookProvider,
  useFeatureIsOn,
} from "@growthbook/growthbook-react";
import { useEffect } from "react";

const growthbook = new GrowthBook({
  apiHost: "<https://cdn.growthbook.io>",
  clientKey: "sdk-xxxxxxxx",
  enableDevMode: true,
  trackingCallback: (experiment, result) => {
    console.log("Viewed Experiment", {
      experimentId: experiment.key,
      variationId: result.key,
    });
  },
});

const PageTitle = () => {
  const enabled = useFeatureIsOn("test");
  if (!enabled) return null;
  return <h1 className="text-4xl">This is my page title!</h1>;
};

export const PageTitleWithGB = () => {
  useEffect(() => {
    growthbook.loadFeatures();
  }, []);

  return (
    <GrowthBookProvider growthbook={growthbook}>
      <PageTitle />
    </GrowthBookProvider>
  );
};

export default PageTitleWithGB;
If I call this in my
NavBar.tsx
which is in turn called in
layout.tsx
- I get null. On another note, I had hoped I could wrap
{children}
in
RootLayout()
in the
GrowthBookProvider
and create the instance there a single time, then be able to put the
useEffect
in the
RootLayout()
function too.. then just evaluate flags anywhere in my app.. should that work? I removed
Metadata
from layout.tsx to make it a client function to test this, to no avail.
Dev Tools shows nothing.
143 Views