Hello! Can anyone help me out with forced rule ? I...
# ask-questions
m
Hello! Can anyone help me out with forced rule ? I created a string feature
display-fees-v2
with the default value
showPriceFeesWithInfo
I added a forced rule that says : if
totalFees
0 then serve
showNoFees
(see screenshot) In my code I added the following :
Copy code
const displayFees = useFeatureIsOn('display-fees-v2');
  const { value } = useExperiment({
    key: 'display-fees-v2',
    variations: ['showPriceFeesWithInfo', 'showFeesWithInfo', 'showFeesWithoutInfo', 'showNoFees'],
  });
  const showPriceFeesWithInfo = value === 'showPriceFeesWithInfo';
  const showFeesWithInfo = value === 'showPriceFeesWithInfo';
  const showFeesWithoutInfo = value === 'showPriceFeesWithInfo';
  const showNoFees = value === 'showPriceFeesWithInfo';
  const growthbook = useGrowthBook();

  useEffect(() => {
    if (!growthbook) return;
    const attributes = growthbook.getAttributes();
    growthbook.setAttributes({
      ...attributes,
      totalFees: totalFees,
    });
    growthbook.refreshFeatures();
  }, [totalFees, growthbook]);
Once I go to my page I see the default variation
showPriceFeesWithInfo
while I want it to be
showNoFees
• How do I force showNoFees when my totalFees are zero ? Thanks!
h
Hi, the
useExperiment()
hook actually is a bypass hook for just running an inline experiment independent of any associated feature flags. Since your override rules and experiment rules are in your feature flag, you should be able to just evaluate the feature flag directly without referencing the experiment in your code.
m
Hi Bryce, thanks your response. I have updated the code with
useFeature
instead of
useExperiment
as follow:
Copy code
const growthbook = useGrowthBook();
  const { value } = useFeature('display-fees-v2');

  const showPriceFeesWithInfo = value === 'showPriceFeesWithInfo';
  const showFeesWithInfo = value === 'showFeesWithInfo';
  const showFeesWithoutInfo = value === 'showFeesWithoutInfo';
  const showNoFees = value === 'showNoFees';

  useEffect(() => {
    if (!growthbook) return;
    growthbook.setAttributes({
      ...growthbook.getAttributes(),
      totalFees: totalFees,
    });
    growthbook.refreshFeatures();
  }, [totalFees, growthbook]);
However, if
totalFees: 0
I still get the
showPriceFeesWithInfo
instead of
showNoFees
And now I see no experiments at all. Is this normal? Do you know what am I doing wrong ?
h
Odd. Can you confirm that your page/component is wrapped by the
<GrowthBookProvider growthbook={gb}>
component? If so, maybe try console logging inside your useEffect hook (before and after the
return
) to see whether that's even firing / updating the user attributes.
m
Hi Bryce, sorry for the late reply. I am seeing your reponse right now. Yes everything is wrapped by the
<GrowthBookProvider growthbook={gb}>
, I logged growthbook in the useEffect and I see my user attributes ebing updated right away, but I still get an empty array for experiments... I guess I will have to use
useExperiment
and implement an if else in my code to get the correct experiment, but it's a shame I don't get what I am doing wrong.