:wave: Hi everyone! Looking to get some help with ...
# announcements
c
👋 Hi everyone! Looking to get some help with setting a forced rule on a feature. When testing, it seems like it is not being applied. Perhaps I am missing something?
f
Hi Jace - can you share a screen shot of your rule(s)?
f
Happy to help. What SDK are you using?
c
Sure one sec. I am using the ReactSDK
f
The rules look fine. It's likely an issue with how the features are loaded in your React code.
c
I just noticed something, I am keying off of id, when in our DB its user_id
Let me try updating this
Also, is ID required on the attributes?
When setting it in react?
f
You can use whatever attributes you want.
c
But does it have to match in order for GB to do the split and know which user to skip?
f
They should match up with what you are using in the rules. So based on the rules in that screenshot, you'll need an
id
attribute
c
Ok
f
Can you share the code you're using to set the features and attributes in the SDK?
c
Sure , one sec
I just added the user_id to my attribute s in the settings
That should now match the column name in the DB
f
if you do
growthbook.evalFeature("your-feature-id")
, can you see what's returned? There should be a
source
property that tells you why a specific value was assigned to the feature
c
One sec let me see what I get
"unknownFeature"
Plus side, I am now seeing the console log tracking call back
I wasnt before
f
ok,
unknownFeature
means the id you are using couldn't be found. That's either caused by a typo in your code or if you're not passing features correctly into the SDK
c
hmmm ok
so part of what I am seeing is that the api when parsing the JSON, features is not part of the object
growthbook.setFeatures(parsed.features) technically never sets
Since features is not part of the parsed object
But, I do see in my network call
f
If you are seeing that in your trackingCallback, then everything should be working fine. If you are fetching the features asynchronously, the first time React renders, the features might not be loaded yet, so it would evaluate to
null
. But when the features load, it will re-render React and it should work fine.
c
No thats not in my callboack
.then((parsed) => { console.log(parsed) growthbook.setFeatures(parsed.features) })
parsed does not have a features object
f
Are you sure? I think the screenshot of the console.log above is coming from a different part of the code
c
in the docs , this is wrong IMO =>
Copy code
.then((parsed) => {
    growthbook.setFeatures(parsed.features);
  });
This actually produces the right response on the eval
Copy code
let r = await fetch(`<https://cdn.growthbook.io/api/features/${gbkey}>`)
				.then((res) => res.json())
				
				growthbook.setFeatures(r.features)
Chaining the responses was not producing the correct eval object in the console log
f
chaining should work fine. You might just need to add
await
in front of the fetch call if you want to evaluate the features immediately.
Copy code
await fetch(`<https://cdn.growthbook.io/api/features/${gbkey}>`)
  .then((res) => res.json())
  .then((parsed) => {
    growthbook.setFeatures(parsed.features);
  })
otherwise, the features will load asynchronously and the features will evaluate to
null
until they fully load. Adding
await
before the fetch will fix that
c
I see ok. Let try that then.
Well I got a little further, I am now facing where further into the app, using the useFeature hook, still gets the "unknownFeature"
Is there way to check if the GB provider is passing the data into my component tree?
NM , I answered that Q
However, I am in the React component dev tool, seeing that the GB provider is showing my feature as "null" , I assume that is not right?
f
it's probably a race condition. If you are setting features inside of a useEffect hook, then the very first render of your application won't have any features defined yet and they will all be
null
. After the useEffect hook finishes, it will populate the features and re-render your application with the correct feature values
Usually not a big deal since all of that happens in milliseconds
c
I see. hmmm ok. Will have to review the app flow then. Thanks for the help and fast responses BTW, just under the gun today to get this working 😉
Do types matter? So for example, my api returns the id of a user as an INT, but the attribute in GrowthBook is set to a STRING in the settings.
Do the types need to match?
Or is that only for when GrowthBook gets the data from the DB ?
f
Javascript is usually pretty lenient with types, but it's better to have them match if you can
c
Ok and I got it working now. And yeah, side note, II found that the attribute type should match the value type you are providing.
Again thanks for the patience and help. Truly appreciate it!