Hello! My project requires me to abstract the feat...
# announcements
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
in the image,
on line 194 is undefined. Hence, line 196 also failed since
is undefined. Is the undefiend json expected? If not, what would I need to do to resolve that? Than kyou.
Hi Karen. Your first
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
Thank you. Another issue that I am running into- I’m seeing
source: unknownFeature
when I invoke the
. 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
. Ideally, I can create a custom hook that calls the
hook so that I can return the feature flag value needed in whichever component needed. 1. Is wrapping
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
need to be called in a specific order or instance? --> trying to understand where does the
error coming from since I could get
to work from your previous comment. Thank you for your help.
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