helpful-carpenter-3208
03/14/2022, 7:49 AMfresh-football-47124
helpful-carpenter-3208
03/14/2022, 7:58 AMfresh-football-47124
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:
import { useFeature } from "@growthbook/growthbook-react";
//...
const config = useFeature("somefeature-config").value;