Hello! My project requires me to abstract the feat...
# announcements
w
Hello! My project requires me to abstract the feature flag implementation logic and implement feature flag as a custom hook. I am not sure if the issue I am running into is caused by the fact that I’m trying to create a custom hook, or it has to do with my configuration of the app. In the
useEffect
in the image,
json
on line 194 is undefined. Hence, line 196 also failed since
json
is undefined. Is the undefiend json expected? If not, what would I need to do to resolve that? Than kyou.
f
Hi Karen. Your first
then
block isn't returning anything. It would need to look like this:
Copy code
.then((res) => {
  console.log('what is res', res)
  return res.json()
})
👍 1
w
Thank you. Another issue that I am running into- I’m seeing
source: unknownFeature
when I invoke the
useFeature(featureName)
. Upon previous conversation, I know that this error is likely caused by the configuration of the app. My goal is to build a custom hook that implements growthbook to the specific component needed. I’m not wrapping entire app in
<GrowthBookProvider>
. Ideally, I can create a custom hook that calls the
useFeature
hook so that I can return the feature flag value needed in whichever component needed. 1. Is wrapping
<GrowthBookProvider>
around a specific component instead of the entire app a plausible use case? Or do I need to wrap the whole app in the GrowthBook Provider? 2. Does
useFeature()
need to be called in a specific order or instance? --> trying to understand where does the
unknownFeature
error coming from since I could get
growthbook.setFeatures
to work from your previous comment. Thank you for your help.
f
The useFeature hook requires GrowthBookProvider somewhere up the component chain. If you don't want to use that, you could just use our JavaScript SDK instead of the React one. One thing to watch out for is that you probably only want to fetch the features from the API once and store it globally. Otherwise, every components using your custom hook will do a new expensive network request.
👍 1