Hi there everyone, I have a quick question about y...
# sdk-react
n
Hi there everyone, I have a quick question about your react-sdk: How does the React SDK handle custom headers when calling the
/api/features/<sdk-key>
endpoint? We need to insert a
User-Agent
header from the client-side mobile app because our test environment blocks requests that lack this header.
s
Unfortunately, the React SDK doesn't support custom headers. As a workaround, you could fetch the payload yourself, and then pass the SDK payload into the GrowthBook init method. However, this approach means you lose some built-in features like auto-refresh and streaming updates
@nutritious-garden-91325 An engineer saw this question and actually said there are two options for passing custom headers:
Copy code
apiHostRequestHeaders
streamingHostRequestHeaders
You can use these in the SDK constructor. This isn't in our docs (🤦) and I hadn't used it, so didn't know. Anyway, let me know if this solves your use case!
n
thanks for following up, @strong-mouse-55694! Do you have any implementation examples you could share?
s
Sure, it's pretty straightforward. You add those options to wherever you instantiate GrowthBook, like this:
Copy code
const growthbook = new GrowthBook({
  apiHostRequestHeaders: {
    "header-name": "header-value",
  },
  streamingHostRequestHeaders: {
    "header-name": "header-value",
  },
  clientKey: "sdk-1234",
  // ...etc
});