Any suggestions on using feature with Nextjs SSR m...
# announcements
h
Any suggestions on using feature with Nextjs SSR mode? I met unknownFeature error when use feature..
f
sure, want to share some code (or via DM)?
are you using the Provider?
h
correct. I just realize it’s my own code bug about setting wrong feature data.. sorry for bother here😇
f
_app.tsx/js
Copy code
import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";

const growthbook = new GrowthBook({
  realtimeKey: "key_NNNN",
  trackingCallback: (experiment, result) => {
    // change to your tracking call:
    track("Experiment Viewed", {
      experimentId: experiment.key,
      variationId: result.variationId,
    });
  },
});

//... inside of App:

useEffect(() => {
    // Load feature definitions JSON from GrowthBook API
    fetch("<https://cdn.growthbook.io/api/features/key_NNNN>")
      .then((res) => res.json())
      .then((json) => {
        growthbook.setFeatures(json.features);
      })
      .catch(() => {
        console.log("Failed to fetch GrowthBook feature definitions");
      });
  }, [router.pathname]);

// ...

return ( <GrowthBookProvider growthbook={growthbook}>
//...
</GrowthBook>);
inside your components:
Copy code
import { useFeature } from "@growthbook/growthbook-react";

//...

 const config = useFeature("somefeature-config").value;
1