https://www.growthbook.io/ logo
#announcements
Title
# announcements
b

bland-microphone-36930

08/23/2023, 7:39 AM
Hello, is there separate sdk for react native?
w

white-fireman-22476

08/23/2023, 7:40 AM
No. There is just the react sdk. Here is an example app: https://github.com/growthbook/examples/tree/main/react-native-cli
b

bland-microphone-36930

08/23/2023, 8:08 AM
Then we can't use Feature hooks(useFeatureIsOn) in react native?
w

white-fireman-22476

08/23/2023, 8:14 AM
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

bland-microphone-36930

08/23/2023, 9:28 AM
useFeatureIsOn is not working in react native, just now I have tested
w

white-fireman-22476

08/23/2023, 9:34 AM
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

bland-microphone-36930

08/23/2023, 9:37 AM
yes
but getFeatureValue expects 2 arguments. useFeatureIsOn will return boolean value with feature name
w

white-fireman-22476

08/23/2023, 9:39 AM
ah, what I meant for booleans is
isOn
. Does that work?
b

bland-microphone-36930

08/23/2023, 9:41 AM
yes working
can I call
and
<GrowthBookProvider growthbook={growthbook}>
is not required in
return
w

white-fireman-22476

08/23/2023, 9:51 AM
I believe that is required.
b

bland-microphone-36930

08/23/2023, 9:52 AM
I have tested it, it is working without
w

white-fireman-22476

08/23/2023, 9:54 AM
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

bland-microphone-36930

08/23/2023, 1:40 PM
Even If I use
GrowthbookProvider
useFeatureIsOn is not working
Is it possible to connect sometime tomorrow?
w

white-fireman-22476

08/23/2023, 2:35 PM
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

bland-microphone-36930

08/24/2023, 5:38 AM
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

white-fireman-22476

09/06/2023, 9:30 AM
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
7 Views