Hello, is there separate sdk for react native?
# announcements
b
Hello, is there separate sdk for react native?
w
No. There is just the react sdk. Here is an example app: https://github.com/growthbook/examples/tree/main/react-native-cli
b
Then we can't use Feature hooks(useFeatureIsOn) in react native?
w
I'm not sure. It could be that the example app is just showing getFeatureValue but useFeatureIsOn might also work. Have you tried it and it is not working?
Our docs don't mention anything about it not working for React Native, so I assume it would work ... otherwise we need to update our documentation.
b
useFeatureIsOn is not working in react native, just now I have tested
w
Thanks for testing that out. I'll reach out to someone who knows more about it and get back to you one way or the other.
Does
getFeatureValue
work?
b
yes
but getFeatureValue expects 2 arguments. useFeatureIsOn will return boolean value with feature name
w
ah, what I meant for booleans is
isOn
. Does that work?
b
yes working
can I call
and
<GrowthBookProvider growthbook={growthbook}>
is not required in
return
w
I believe that is required.
b
I have tested it, it is working without
w
hmm, ok I'll ask about that too and get back to you. It might be awhile until someone responds, but hopefully within the next day.
👍 1
useFeatureIsOn
should work for react native... but you do need to set the GrowthbookProvider because that gives the components below it the growthbook context.
If you are just calling the js-sdk functions like
isOn
directly on the growthbook object then it is not needed.
b
Even If I use
GrowthbookProvider
useFeatureIsOn is not working
Is it possible to connect sometime tomorrow?
w
What is not working about it?
useFeatureIsOn
is calling
isOn
under the hood: https://github.com/growthbook/growthbook/blob/49d9852c46e574c0f3fad25077adb68a230367ba/packages/sdk-react/src/GrowthBookReact.tsx#L108 if you setting the GrowthbookProvider it should be able to load the growthbook object from the context and use it. Are you seeing an error message or anything?
Are you calling it maybe outside of an inner child component?
b
It is not returning any error. But auto refresh is not working.
Hi @white-fireman-22476 how can we do auto refresh in react native
w
As far as I am aware we will use Server Send Events by default: https://docs.growthbook.io/lib/react#streaming-updates. Are you using Growthbook Cloud or Growthbook Proxy server as SSE only works in those cases.
However doing SSE on React Native requires additional libraries normally and I don't know if we have set that up to work yet. Perhaps our docs need to mention that if it is not working. Doing a quick GPT query I see:
• React Native does not support the native EventSource API, which is the standard way of creating an SSE connection in the browser. To use SSE on React Native, you need to use a third-party library that provides a polyfill or a wrapper for the EventSource API. For example, you can use [react-native-event-source] or [rn-eventsource], which are both npm packages that you can install and import in your React Native project.
• React Native does not support the native fetch API, which is often used to send requests to the server that initiates the SSE connection. To use fetch on React Native, you need to use a third-party library that provides a polyfill or a wrapper for the fetch API. For example, you can use [react-native-fetch-polyfill] or [whatwg-fetch], which are both npm packages that you can install and import in your React Native project.
• React Native does not support the native URL API, which is sometimes used to parse and manipulate URLs for the SSE connection. To use URL on React Native, you need to use a third-party library that provides a polyfill or a wrapper for the URL API. For example, you can use [react-native-url-polyfill] or [url-polyfill], which are both npm packages that you can install and import in your React Native project.
By using these libraries, you can create and use an SSE connection on React Native similar to how you would do it on the web.
Alternatively you can refresh on your own at any time by doing
gb.refreshFeatures()
https://docs.growthbook.io/lib/js#nodejs shows how to use polyfills