Sometime growthbook's hook useFeature().source returning "defaultValue" as value

337 views Asked by At

hi i am using A/B testing with growthbook i added a feature stroke-care_page

enter image description here

inside this feature i added two Experiment rule with 50%-50% coverage enter image description here

In Code in _app.js

const growthbook = new GrowthBook({
  enableDevMode: true,
  trackingCallback: (experiment, result) => {
    console.log(" ~ file: _app.js ~ experiment", experiment)
    console.log(" ~ file: _app.js ~ result", result)
  },
});

useEffect(()=>{
fetchData()
},[])

const fetchData = async () => {
  const machine_id = getMachineId()
    fetch(FEATURES_ENDPOINT)
      .then((res) => res.json())
      .then((json) => {
        growthbook.setFeatures(json.features);
      });

    growthbook.setAttributes({
      id: "user",
      loggedIn: true,
      deviceId: machine_id,
      employee: true,
      company: "ABC",
      browser: navigator.userAgent
    });
}

in page.js

growthbook's hook useFeature() hook to get value of a feature

const feature = useFeature("stroke-care_page");

useEffect(() => { 
 if (feature.source === "experiment") 
 { 
  setGrowthbookContent(feature.value)           
 } 
}, [feature.source])

but sometime feature.source returnning defaultValue

its should return experiment always

and i try to log conosle.log(feature) its value this sometime

enter image description here

**expected value ** sometime is work fine

enter image description here

i dont know why growthbook work like this?

0

There are 0 answers